diff options
Diffstat (limited to 'stm')
| -rw-r--r-- | stm/i2c.c | 10 | ||||
| -rw-r--r-- | stm/led.c | 56 | ||||
| -rw-r--r-- | stm/main.c | 2 | ||||
| -rw-r--r-- | stm/servo.c | 10 | ||||
| -rw-r--r-- | stm/usrsw.c | 7 |
5 files changed, 35 insertions, 50 deletions
@@ -329,14 +329,8 @@ static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_stop_obj, i2c_obj_stop); static const mp_obj_type_t i2c_obj_type = { { &mp_const_type }, "I2C", - i2c_obj_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { // method list + .print = i2c_obj_print, + .methods = { { "start", &i2c_obj_start_obj }, { "write", &i2c_obj_write_obj }, { "read", &i2c_obj_read_obj }, @@ -8,10 +8,10 @@ #include "led.h" /* LED numbers, used internally */ -#define PYB_LED_1 (1) -#define PYB_LED_2 (2) -#define PYB_LED_3 (3) -#define PYB_LED_4 (4) +#define PYB_LED_1 (0) +#define PYB_LED_2 (1) +#define PYB_LED_3 (2) +#define PYB_LED_4 (3) #if defined(PYBOARD) #define PYB_LED1_PORT (GPIOA) @@ -86,22 +86,22 @@ void led_state(pyb_led_t led, int state) { switch (led) { case PYB_LED_1: - pin = PYB_LED1_PIN; - port = PYB_LED1_PORT; + pin = PYB_LED1_PIN; + port = PYB_LED1_PORT; break; case PYB_LED_2: - pin = PYB_LED2_PIN; - port = PYB_LED2_PORT; + pin = PYB_LED2_PIN; + port = PYB_LED2_PORT; break; case PYB_LED_3: - pin = PYB_LED3_PIN; - port = PYB_LED3_PORT; + pin = PYB_LED3_PIN; + port = PYB_LED3_PORT; break; case PYB_LED_4: - pin = PYB_LED4_PIN; - port = PYB_LED4_PORT; + pin = PYB_LED4_PIN; + port = PYB_LED4_PORT; break; - default: + default: return; } @@ -120,27 +120,27 @@ void led_toggle(pyb_led_t led) { switch (led) { case PYB_LED_1: - pin = PYB_LED1_PIN; - port = PYB_LED1_PORT; + pin = PYB_LED1_PIN; + port = PYB_LED1_PORT; break; case PYB_LED_2: - pin = PYB_LED2_PIN; - port = PYB_LED2_PORT; + pin = PYB_LED2_PIN; + port = PYB_LED2_PORT; break; case PYB_LED_3: - pin = PYB_LED3_PIN; - port = PYB_LED3_PORT; + pin = PYB_LED3_PIN; + port = PYB_LED3_PORT; break; case PYB_LED_4: - pin = PYB_LED4_PIN; - port = PYB_LED4_PORT; + pin = PYB_LED4_PIN; + port = PYB_LED4_PORT; break; - default: + default: return; } if (!(port->ODR & pin)) { - // turn LED off + // turn LED off PYB_LED_OFF(port, pin); } else { // turn LED on (output low) @@ -179,14 +179,8 @@ static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); static const mp_obj_type_t led_obj_type = { { &mp_const_type }, "Led", - led_obj_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { // method list + .print = led_obj_print, + .methods = { { "on", &led_obj_on_obj }, { "off", &led_obj_off_obj }, { NULL, NULL }, diff --git a/stm/main.c b/stm/main.c index 2121742fd..07c974eff 100644 --- a/stm/main.c +++ b/stm/main.c @@ -699,7 +699,7 @@ static const mp_obj_type_t file_obj_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - { // method list + .methods = { { "read", &file_obj_read_obj }, { "write", &file_obj_write_obj }, { "close", &file_obj_close_obj }, diff --git a/stm/servo.c b/stm/servo.c index 1e31db514..31190ce79 100644 --- a/stm/servo.c +++ b/stm/servo.c @@ -140,14 +140,8 @@ static MP_DEFINE_CONST_FUN_OBJ_2(servo_obj_angle_obj, servo_obj_angle); static const mp_obj_type_t servo_obj_type = { { &mp_const_type }, "Servo", - servo_obj_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { // method list + .print = servo_obj_print, + .methods = { { "angle", &servo_obj_angle_obj }, { NULL, NULL }, } diff --git a/stm/usrsw.c b/stm/usrsw.c index 1feb27173..9d1ee50ff 100644 --- a/stm/usrsw.c +++ b/stm/usrsw.c @@ -12,6 +12,7 @@ #if defined (PYBOARD) #define USRSW_PORT (GPIOA) #define USRSW_PIN (GPIO_Pin_13) + #define USRSW_PUPD (GPIO_PuPd_UP) #define USRSW_EXTI_PIN (EXTI_PinSource13) #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOA) #define USRSW_EXTI_LINE (EXTI_Line13) @@ -20,18 +21,20 @@ #elif defined (STM32F4DISC) #define USRSW_PORT (GPIOA) #define USRSW_PIN (GPIO_Pin_0) + #define USRSW_PUPD (GPIO_PuPd_NOPULL) #define USRSW_EXTI_PIN (EXTI_PinSource0) #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOA) #define USRSW_EXTI_LINE (EXTI_Line0) #define USRSW_EXTI_IRQN (EXTI0_IRQn) #define USRSW_EXTI_EDGE (EXTI_Trigger_Falling) -#endif +#endif + void switch_init(void) { // make it an input with pull-up GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = USRSW_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; /* allow external pull up/down */ + GPIO_InitStructure.GPIO_PuPd = USRSW_PUPD; GPIO_Init(USRSW_PORT, &GPIO_InitStructure); // the rest does the EXTI interrupt |
