stmhal: Remove PYBVxx defines and use config vars for UART/CAN names.

Now all stmhal-based boards can name their peripherals (if they want) to
any string.
This commit is contained in:
Damien George 2015-05-27 16:51:04 +01:00
parent 9ae3fc6523
commit 1775b65e07
7 changed files with 48 additions and 35 deletions

View File

@ -1,5 +1,3 @@
#define PYBV10
#define MICROPY_HW_BOARD_NAME "PYBv1.0"
#define MICROPY_HW_MCU_NAME "STM32F405RG"
#define MICROPY_PY_SYS_PLATFORM "pyboard"
@ -29,18 +27,22 @@
#define MICROPY_HW_RTC_USE_LSE (1)
// UART config
#define MICROPY_HW_UART1_NAME "XB"
#define MICROPY_HW_UART1_PORT (GPIOB)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_NAME "YB"
#define MICROPY_HW_UART3_PORT (GPIOB)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
#define MICROPY_HW_UART4_NAME "XA"
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_NAME "YA"
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
@ -52,6 +54,10 @@
#define MICROPY_HW_I2C2_SCL (pin_B10)
#define MICROPY_HW_I2C2_SDA (pin_B11)
// CAN busses
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
#define MICROPY_HW_USRSW_PIN (pin_B3)
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)

View File

@ -1,5 +1,3 @@
#define PYBV3
#define MICROPY_HW_BOARD_NAME "PYBv3"
#define MICROPY_HW_MCU_NAME "STM32F405RG"

View File

@ -1,7 +1,6 @@
#define PYBV4
#define MICROPY_HW_BOARD_NAME "PYBv4"
#define MICROPY_HW_MCU_NAME "STM32F405RG"
#define MICROPY_PY_SYS_PLATFORM "pyboard"
#define MICROPY_HW_HAS_SWITCH (1)
#define MICROPY_HW_HAS_SDCARD (1)
@ -28,18 +27,22 @@
#define MICROPY_HW_RTC_USE_LSE (1)
// UART config
#define MICROPY_HW_UART1_NAME "XB"
#define MICROPY_HW_UART1_PORT (GPIOB)
#define MICROPY_HW_UART1_PINS (GPIO_PIN_6 | GPIO_PIN_7)
#define MICROPY_HW_UART2_PORT (GPIOA)
#define MICROPY_HW_UART2_PINS (GPIO_PIN_2 | GPIO_PIN_3)
#define MICROPY_HW_UART2_RTS (GPIO_PIN_1)
#define MICROPY_HW_UART2_CTS (GPIO_PIN_0)
#define MICROPY_HW_UART3_NAME "YB"
#define MICROPY_HW_UART3_PORT (GPIOB)
#define MICROPY_HW_UART3_PINS (GPIO_PIN_10 | GPIO_PIN_11)
#define MICROPY_HW_UART3_RTS (GPIO_PIN_14)
#define MICROPY_HW_UART3_CTS (GPIO_PIN_13)
#define MICROPY_HW_UART4_NAME "XA"
#define MICROPY_HW_UART4_PORT (GPIOA)
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
#define MICROPY_HW_UART6_NAME "YA"
#define MICROPY_HW_UART6_PORT (GPIOC)
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
@ -51,6 +54,10 @@
#define MICROPY_HW_I2C2_SCL (pin_B10)
#define MICROPY_HW_I2C2_SDA (pin_B11)
// CAN busses
#define MICROPY_HW_CAN1_NAME "YA" // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
#define MICROPY_HW_CAN2_NAME "YB" // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
#define MICROPY_HW_USRSW_PIN (pin_B3)
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)

View File

@ -352,11 +352,13 @@ STATIC mp_obj_t pyb_can_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
if (MP_OBJ_IS_STR(args[0])) {
const char *port = mp_obj_str_get_str(args[0]);
if (0) {
#if defined(PYBV10)
} else if (strcmp(port, "YA") == 0) {
o->can_id = PYB_CAN_YA;
} else if (strcmp(port, "YB") == 0) {
o->can_id = PYB_CAN_YB;
#ifdef MICROPY_HW_CAN1_NAME
} else if (strcmp(port, MICROPY_HW_CAN1_NAME) == 0) {
o->can_id = PYB_CAN_1;
#endif
#ifdef MICROPY_HW_CAN2_NAME
} else if (strcmp(port, MICROPY_HW_CAN2_NAME) == 0) {
o->can_id = PYB_CAN_2;
#endif
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "CAN port %s does not exist", port));

View File

@ -27,12 +27,6 @@
#define PYB_CAN_1 (1)
#define PYB_CAN_2 (2)
// aliases for pyboard
#if defined(PYBV10)
#define PYB_CAN_YA PYB_CAN_1 // CAN1 on RX,TX = Y3,Y4 = PB8,PB9
#define PYB_CAN_YB PYB_CAN_2 // CAN2 on RX,TX = Y5,Y6 = PB12,PB13
#endif
extern const mp_obj_type_t pyb_can_type;
void can_init0(void);

View File

@ -504,16 +504,30 @@ STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t
if (MP_OBJ_IS_STR(args[0])) {
const char *port = mp_obj_str_get_str(args[0]);
if (0) {
#if defined(PYBV10)
} else if (strcmp(port, "XA") == 0) {
uart_id = PYB_UART_XA;
} else if (strcmp(port, "XB") == 0) {
uart_id = PYB_UART_XB;
} else if (strcmp(port, "YA") == 0) {
uart_id = PYB_UART_YA;
} else if (strcmp(port, "YB") == 0) {
uart_id = PYB_UART_YB;
#endif
#ifdef MICROPY_HW_UART1_NAME
} else if (strcmp(port, MICROPY_HW_UART1_NAME) == 0) {
uart_id = PYB_UART_1;
#endif
#ifdef MICROPY_HW_UART2_NAME
} else if (strcmp(port, MICROPY_HW_UART2_NAME) == 0) {
uart_id = PYB_UART_2;
#endif
#ifdef MICROPY_HW_UART3_NAME
} else if (strcmp(port, MICROPY_HW_UART3_NAME) == 0) {
uart_id = PYB_UART_3;
#endif
#ifdef MICROPY_HW_UART4_NAME
} else if (strcmp(port, MICROPY_HW_UART4_NAME) == 0) {
uart_id = PYB_UART_4;
#endif
#ifdef MICROPY_HW_UART5_NAME
} else if (strcmp(port, MICROPY_HW_UART5_NAME) == 0) {
uart_id = PYB_UART_5;
#endif
#ifdef MICROPY_HW_UART6_NAME
} else if (strcmp(port, MICROPY_HW_UART6_NAME) == 0) {
uart_id = PYB_UART_6;
#endif
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) does not exist", port));
}

View File

@ -32,14 +32,6 @@ typedef enum {
PYB_UART_4 = 4,
PYB_UART_5 = 5,
PYB_UART_6 = 6,
#if defined(PYBV10)
PYB_UART_XA = 4, // UART4 on X1, X2 = PA0, PA1
PYB_UART_XB = 1, // USART1 on X9, X10 = PB6, PB7
PYB_UART_YA = 6, // USART6 on Y1, Y2 = PC6, PC7
PYB_UART_YB = 3, // USART3 on Y9, Y10 = PB10, PB11
#endif
} pyb_uart_t;
typedef struct _pyb_uart_obj_t pyb_uart_obj_t;