Skip to content

Commit

Permalink
esp32: Marge with master.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Campora committed Jun 15, 2017
1 parent 46f7a10 commit 18f1fd8
Show file tree
Hide file tree
Showing 25 changed files with 195 additions and 151 deletions.
45 changes: 14 additions & 31 deletions esp32/boards/LOPY/mpconfigboard.h
Expand Up @@ -18,39 +18,22 @@

#define MICROPY_HW_FLASH_SIZE (4 * 1024 * 1024)

#if defined(OEM_VERSION)
#define MICROPY_LPWAN_DIO_PIN

#define MICROPY_HW_ANTENNA_DIVERSITY (0)
extern uint32_t micropy_hw_flash_size;

#define MICROPY_LPWAN_RESET_PIN_NUM
#define MICROPY_LPWAN_RESET_PIN_NAME
#define MICROPY_LPWAN_RESET_PIN
#define MICROPY_LPWAN_USE_RESET_PIN 0
extern bool micropy_hw_antenna_diversity;
extern uint32_t micropy_hw_antenna_diversity_pin_num;

#define MICROPY_LPWAN_DIO_PIN_NUM (23)
#define MICROPY_LPWAN_DIO_PIN_NAME GPIO23
#define MICROPY_LPWAN_DIO_PIN (pin_GPIO23)
extern bool micropy_lpwan_use_reset_pin;
extern uint32_t micropy_lpwan_reset_pin_num;
extern uint32_t micropy_lpwan_reset_pin_index;
extern void * micropy_lpwan_reset_pin;

#define MICROPY_LPWAN_NCS_PIN_NUM (18)
#define MICROPY_LPWAN_NCS_PIN_NAME GPIO18
#define MICROPY_LPWAN_NCS_PIN (pin_GPIO18)
extern uint32_t micropy_lpwan_dio_pin_num;
extern uint32_t micropy_lpwan_dio_pin_index;
extern void * micropy_lpwan_dio_pin;

#else

#define MICROPY_HW_ANTENNA_DIVERSITY (1)
#define MICROPY_HW_ANTENNA_DIVERSITY_PIN_NUM (16)

#define MICROPY_LPWAN_RESET_PIN_NUM (18)
#define MICROPY_LPWAN_RESET_PIN_NAME GPIO18
#define MICROPY_LPWAN_RESET_PIN (pin_GPIO18)
#define MICROPY_LPWAN_USE_RESET_PIN 1

#define MICROPY_LPWAN_DIO_PIN_NUM (23)
#define MICROPY_LPWAN_DIO_PIN_NAME GPIO23
#define MICROPY_LPWAN_DIO_PIN (pin_GPIO23)

#define MICROPY_LPWAN_NCS_PIN_NUM (17)
#define MICROPY_LPWAN_NCS_PIN_NAME GPIO17
#define MICROPY_LPWAN_NCS_PIN (pin_GPIO17)

#endif
extern uint32_t micropy_lpwan_ncs_pin_num;
extern uint32_t micropy_lpwan_ncs_pin_index;
extern void * micropy_lpwan_ncs_pin;
22 changes: 13 additions & 9 deletions esp32/boards/SIPY/mpconfigboard.h
Expand Up @@ -18,16 +18,20 @@

#define MICROPY_HW_FLASH_SIZE (4 * 1024 * 1024)

#if defined(OEM_VERSION)
extern uint32_t micropy_hw_flash_size;

#define MICROPY_HW_ANTENNA_DIVERSITY (0)
extern bool micropy_hw_antenna_diversity;
extern uint32_t micropy_hw_antenna_diversity_pin_num;

#else
extern bool micropy_lpwan_use_reset_pin;
extern uint32_t micropy_lpwan_reset_pin_num;
extern uint32_t micropy_lpwan_reset_pin_index;
extern void * micropy_lpwan_reset_pin;

#define MICROPY_HW_ANTENNA_DIVERSITY (1)
#define MICROPY_HW_ANTENNA_DIVERSITY_PIN_NUM (16)
extern uint32_t micropy_lpwan_dio_pin_num;
extern uint32_t micropy_lpwan_dio_pin_index;
extern void * micropy_lpwan_dio_pin;

#define MICROPY_LPWAN_DIO_PIN_NUM (23)
#define MICROPY_LPWAN_DIO_PIN (pin_GPIO23)

#endif
extern uint32_t micropy_lpwan_ncs_pin_num;
extern uint32_t micropy_lpwan_ncs_pin_index;
extern void * micropy_lpwan_ncs_pin;
19 changes: 13 additions & 6 deletions esp32/boards/WIPY/mpconfigboard.h
Expand Up @@ -18,13 +18,20 @@

#define MICROPY_HW_FLASH_SIZE (4 * 1024 * 1024)

#if defined(OEM_VERSION)
extern uint32_t micropy_hw_flash_size;

#define MICROPY_HW_ANTENNA_DIVERSITY (0)
extern bool micropy_hw_antenna_diversity;
extern uint32_t micropy_hw_antenna_diversity_pin_num;

#else
extern bool micropy_lpwan_use_reset_pin;
extern uint32_t micropy_lpwan_reset_pin_num;
extern uint32_t micropy_lpwan_reset_pin_index;
extern void * micropy_lpwan_reset_pin;

#define MICROPY_HW_ANTENNA_DIVERSITY (1)
#define MICROPY_HW_ANTENNA_DIVERSITY_PIN_NUM (16)
extern uint32_t micropy_lpwan_dio_pin_num;
extern uint32_t micropy_lpwan_dio_pin_index;
extern void * micropy_lpwan_dio_pin;

#endif
extern uint32_t micropy_lpwan_ncs_pin_num;
extern uint32_t micropy_lpwan_ncs_pin_index;
extern void * micropy_lpwan_ncs_pin;
4 changes: 3 additions & 1 deletion esp32/fatfs/src/drivers/sd_diskio.c
Expand Up @@ -35,6 +35,8 @@
#define CARD_VERSION_1 0
#define CARD_VERSION_2 1

#define SD_CARD_MAX_FREQUENCY_KHZ 10000

//*****************************************************************************
// Disk Info for attached disk
//*****************************************************************************
Expand All @@ -54,7 +56,7 @@ DSTATUS sd_disk_init (void) {
{
.flags = SDMMC_HOST_FLAG_1BIT,
.slot = SDMMC_HOST_SLOT_1,
.max_freq_khz = SDMMC_FREQ_DEFAULT,
.max_freq_khz = SD_CARD_MAX_FREQUENCY_KHZ,
.io_voltage = 3.3f,
.init = &sdmmc_host_init,
.set_bus_width = &sdmmc_host_set_bus_width,
Expand Down
4 changes: 0 additions & 4 deletions esp32/frozen/_boot.py
@@ -1,8 +1,4 @@
# _boot.py -- always run on boot-up, even during safe boot
import os
from machine import UART
UART(1, 115200)
UART(2, 115200)
os.dupterm(UART(0, 115200))
UART(1).deinit()
UART(2).deinit()
Binary file modified esp32/lib/libbt.a
Binary file not shown.
Binary file modified esp32/lib/libdriver.a
Binary file not shown.
Binary file modified esp32/lib/libesp32.a
Binary file not shown.
Binary file modified esp32/lib/libfreertos.a
Binary file not shown.
Binary file modified esp32/lib/liblog.a
Binary file not shown.
Binary file modified esp32/lib/liblwip.a
Binary file not shown.
Binary file modified esp32/lib/libmbedtls.a
Binary file not shown.
Binary file removed esp32/lib/libmdns.a
Binary file not shown.
Binary file modified esp32/lib/libnghttp.a
Binary file not shown.
6 changes: 3 additions & 3 deletions esp32/lora/board.h
Expand Up @@ -59,14 +59,14 @@ Maintainer: Miguel Luis and Gregory Cristian
* Board MCU pins definitions
*/

#define RADIO_RESET MICROPY_LPWAN_RESET_PIN_NAME
#define RADIO_RESET micropy_lpwan_reset_pin_index

#define RADIO_MOSI GPIO27
#define RADIO_MISO GPIO19
#define RADIO_SCLK GPIO5
#define RADIO_NSS MICROPY_LPWAN_NCS_PIN_NAME
#define RADIO_NSS micropy_lpwan_ncs_pin_index

#define RADIO_DIO MICROPY_LPWAN_DIO_PIN_NAME
#define RADIO_DIO micropy_lpwan_dio_pin_index

void BoardInitPeriph( void );

Expand Down
27 changes: 3 additions & 24 deletions esp32/lora/gpio-board.c
Expand Up @@ -31,33 +31,12 @@ Maintainer: Miguel Luis and Gregory Cristian
#include "pins.h"

pin_obj_t *gpio_board_map[NBR_GP_PINS] = {
&pin_GPIO3,
&pin_GPIO1,
&pin_GPIO0,
&pin_GPIO4,
&pin_GPIO15,
&pin_GPIO5,
&pin_GPIO27,
&pin_GPIO19,
&pin_GPIO2,
&pin_GPIO12,
&pin_GPIO13,
&pin_GPIO22,
&pin_GPIO21,
&pin_GPIO14,
&pin_GPIO25,
&pin_GPIO26,
&pin_GPIO33,
&pin_GPIO32,
&pin_GPI34,
&pin_GPI35,
&pin_GPI39,
&pin_GPI38,
&pin_GPI36,
&pin_GPI37,
&pin_GPIO17,
&pin_GPIO18,
&pin_GPIO23,
&pin_GPIO5,
&pin_GPIO27,
&pin_GPIO19,
};

/*!
Expand Down
4 changes: 1 addition & 3 deletions esp32/lora/pinName-board.h
Expand Up @@ -34,8 +34,6 @@ Maintainer: Miguel Luis and Gregory Cristian
* ESP32 Pin Names
*/
#define MCU_PINS \
GPIO3 = 0, GPIO1, GPIO0, GPIO4, GPIO15, GPIO5, GPIO27, GPIO19, GPIO2, GPIO12, \
GPIO13, GPIO22, GPIO21, GPIO14, GPIO25, GPIO26, GPIO33, GPIO32, GPI34, GPI35, \
GPI39, GPI38, GPI36, GPI37, GPIO17, GPIO18, GPIO23, NBR_GP_PINS
GPIO17 = 0, GPIO18, GPIO23, GPIO5, GPIO27, GPIO19, NBR_GP_PINS

#endif // __PIN_NAME_MCU_H__
60 changes: 58 additions & 2 deletions esp32/main.c
Expand Up @@ -43,13 +43,35 @@
#include "soc/dport_reg.h"
#include "esp_log.h"

#include "py/mpconfig.h"
#include "py/mpstate.h"
#include "py/runtime.h"
#include "mptask.h"
#include "machpin.h"
#include "pins.h"

/******************************************************************************
DECLARE PUBLIC DATA
******************************************************************************/
StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__((aligned (4)));
StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__((aligned (8)));

// board configuration options from mpconfigboard.h
uint32_t micropy_hw_flash_size;

bool micropy_hw_antenna_diversity;
uint32_t micropy_hw_antenna_diversity_pin_num;

uint32_t micropy_lpwan_reset_pin_num;
uint32_t micropy_lpwan_reset_pin_index;
void * micropy_lpwan_reset_pin;
bool micropy_lpwan_use_reset_pin;

uint32_t micropy_lpwan_dio_pin_num;
uint32_t micropy_lpwan_dio_pin_index;
void * micropy_lpwan_dio_pin;

uint32_t micropy_lpwan_ncs_pin_num;
uint32_t micropy_lpwan_ncs_pin_index;
void * micropy_lpwan_ncs_pin;

/******************************************************************************
DECLARE PRIVATE DATA
Expand All @@ -68,6 +90,40 @@ void app_main(void) {
// initalize the non-volatile flash space
nvs_flash_init();

esp_chip_info_t chip_info;
esp_chip_info(&chip_info);

if (chip_info.revision > 0) {
micropy_hw_antenna_diversity = false;
micropy_lpwan_use_reset_pin = false;

micropy_lpwan_ncs_pin_index = 1;
micropy_lpwan_ncs_pin_num = 18;
micropy_lpwan_ncs_pin = &pin_GPIO18;

micropy_lpwan_dio_pin_index = 2;
micropy_lpwan_dio_pin_num = 23;
micropy_lpwan_dio_pin = &pin_GPIO23;
} else {
micropy_hw_antenna_diversity = true;
micropy_hw_antenna_diversity_pin_num = 16;

micropy_lpwan_ncs_pin_index = 0;
micropy_lpwan_ncs_pin_num = 17;
micropy_lpwan_ncs_pin = &pin_GPIO17;

micropy_lpwan_reset_pin_index = 1;
micropy_lpwan_reset_pin_num = 18;
micropy_lpwan_reset_pin = &pin_GPIO18;
micropy_lpwan_use_reset_pin = true;

micropy_lpwan_dio_pin_index = 2;
micropy_lpwan_dio_pin_num = 23;
micropy_lpwan_dio_pin = &pin_GPIO23;
}

micropy_hw_flash_size = spi_flash_get_chip_size();

// create the MicroPython task
xTaskCreateStaticPinnedToCore(TASK_Micropython, "MicroPy", MICROPY_TASK_STACK_LEN, NULL,
MICROPY_TASK_PRIORITY, mpTaskStack, &mpTaskTCB, 0);
Expand Down
10 changes: 5 additions & 5 deletions esp32/mods/machpin.c
Expand Up @@ -277,15 +277,15 @@ STATIC IRAM_ATTR void machpin_intr_process (void* arg) {
uint32_t gpio_intr_status = READ_PERI_REG(GPIO_STATUS_REG);
uint32_t gpio_intr_status_h = READ_PERI_REG(GPIO_STATUS1_REG);

#ifdef MICROPY_LPWAN_DIO_PIN_NUM
#ifdef MICROPY_LPWAN_DIO_PIN
// fast path for the LPWAN DIO interrupt
if (gpio_intr_status & (1 << MICROPY_LPWAN_DIO_PIN_NUM)) {
((void(*)(void))MICROPY_LPWAN_DIO_PIN.handler)();
if (gpio_intr_status & (1 << micropy_lpwan_dio_pin_num)) {
((void(*)(void))((pin_obj_t *)micropy_lpwan_dio_pin)->handler)();

// clear this bit from the interrupt status
gpio_intr_status &= ~(1 << MICROPY_LPWAN_DIO_PIN_NUM);
gpio_intr_status &= ~(1 << micropy_lpwan_dio_pin_num);
// clear the interrupt
SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, (1 << MICROPY_LPWAN_DIO_PIN_NUM));
SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, (1 << micropy_lpwan_dio_pin_num));
}
#endif

Expand Down

0 comments on commit 18f1fd8

Please sign in to comment.