Browse Source

stm: rename sw_xx to switch_xx; change Python bindings to new version.

pull/88/head
Damien George 11 years ago
parent
commit
823877bce0
  1. 10
      stm/main.c
  2. 10
      stm/usrsw.c
  3. 9
      stm/usrsw.h

10
stm/main.c

@ -773,7 +773,7 @@ int main(void) {
led_state(PYB_LED_G1, 1); led_state(PYB_LED_G1, 1);
// more sub-system init // more sub-system init
sw_init(); switch_init();
storage_init(); storage_init();
//usart_init(); disabled while wi-fi is enabled //usart_init(); disabled while wi-fi is enabled
@ -822,7 +822,7 @@ soft_reset:
rt_store_attr(m, qstr_from_str_static("gc"), rt_make_function_0(pyb_gc)); rt_store_attr(m, qstr_from_str_static("gc"), rt_make_function_0(pyb_gc));
rt_store_attr(m, qstr_from_str_static("delay"), rt_make_function_1(pyb_delay)); rt_store_attr(m, qstr_from_str_static("delay"), rt_make_function_1(pyb_delay));
rt_store_attr(m, qstr_from_str_static("led"), rt_make_function_1(pyb_led)); rt_store_attr(m, qstr_from_str_static("led"), rt_make_function_1(pyb_led));
rt_store_attr(m, qstr_from_str_static("switch"), rt_make_function_0(pyb_sw)); rt_store_attr(m, qstr_from_str_static("switch"), (mp_obj_t)&pyb_switch_obj);
rt_store_attr(m, qstr_from_str_static("servo"), rt_make_function_2(pyb_servo_set)); rt_store_attr(m, qstr_from_str_static("servo"), rt_make_function_2(pyb_servo_set));
rt_store_attr(m, qstr_from_str_static("pwm"), rt_make_function_2(pyb_pwm_set)); rt_store_attr(m, qstr_from_str_static("pwm"), rt_make_function_2(pyb_pwm_set));
rt_store_attr(m, qstr_from_str_static("accel"), (mp_obj_t)&pyb_mma_read_obj); rt_store_attr(m, qstr_from_str_static("accel"), (mp_obj_t)&pyb_mma_read_obj);
@ -848,10 +848,10 @@ soft_reset:
// check if user switch held (initiates reset of filesystem) // check if user switch held (initiates reset of filesystem)
bool reset_filesystem = false; bool reset_filesystem = false;
if (sw_get()) { if (switch_get()) {
reset_filesystem = true; reset_filesystem = true;
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
if (!sw_get()) { if (!switch_get()) {
reset_filesystem = false; reset_filesystem = false;
break; break;
} }
@ -1122,7 +1122,7 @@ soft_reset:
data[2] = -2; data[2] = -2;
data[3] = 0; data[3] = 0;
for (;;) { for (;;) {
if (sw_get()) { if (switch_get()) {
data[0] = 0x01; // 0x04 is middle, 0x02 is right data[0] = 0x01; // 0x04 is middle, 0x02 is right
} else { } else {
data[0] = 0x00; data[0] = 0x00;

10
stm/usrsw.c

@ -12,7 +12,7 @@
#define PYB_USRSW_PORT (GPIOA) #define PYB_USRSW_PORT (GPIOA)
#define PYB_USRSW_PIN (GPIO_Pin_13) #define PYB_USRSW_PIN (GPIO_Pin_13)
void sw_init(void) { void switch_init(void) {
// make it an input with pull-up // make it an input with pull-up
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = PYB_USRSW_PIN; GPIO_InitStructure.GPIO_Pin = PYB_USRSW_PIN;
@ -45,7 +45,7 @@ void sw_init(void) {
NVIC_Init(&NVIC_InitStructure); NVIC_Init(&NVIC_InitStructure);
} }
int sw_get(void) { int switch_get(void) {
if (PYB_USRSW_PORT->IDR & PYB_USRSW_PIN) { if (PYB_USRSW_PORT->IDR & PYB_USRSW_PIN) {
// pulled high, so switch is not pressed // pulled high, so switch is not pressed
return 0; return 0;
@ -58,12 +58,12 @@ int sw_get(void) {
/******************************************************************************/ /******************************************************************************/
/* Micro Python bindings */ /* Micro Python bindings */
mp_obj_t pyb_sw(void) { static mp_obj_t pyb_switch(void) {
if (sw_get()) { if (switch_get()) {
return mp_const_true; return mp_const_true;
} else { } else {
return mp_const_false; return mp_const_false;
} }
} }
MP_DEFINE_CONST_FUN_OBJ_0(pyb_switch_obj, pyb_switch);

9
stm/usrsw.h

@ -1,7 +1,4 @@
#ifndef __USRSW_H__ void switch_init(void);
#define __USRSW_H__ int switch_get(void);
void sw_init(void);
int sw_get(void);
mp_obj_t pyb_sw(void); MP_DECLARE_CONST_FUN_OBJ(pyb_switch_obj);
#endif //__USRSW_H__

Loading…
Cancel
Save