summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--stm/main.c10
-rw-r--r--stm/usrsw.c10
-rw-r--r--stm/usrsw.h9
3 files changed, 13 insertions, 16 deletions
diff --git a/stm/main.c b/stm/main.c
index f6aa42abf0..2121742fd8 100644
--- a/stm/main.c
+++ b/stm/main.c
@@ -773,7 +773,7 @@ int main(void) {
led_state(PYB_LED_G1, 1);
// more sub-system init
- sw_init();
+ switch_init();
storage_init();
//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("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("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("pwm"), rt_make_function_2(pyb_pwm_set));
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)
bool reset_filesystem = false;
- if (sw_get()) {
+ if (switch_get()) {
reset_filesystem = true;
for (int i = 0; i < 50; i++) {
- if (!sw_get()) {
+ if (!switch_get()) {
reset_filesystem = false;
break;
}
@@ -1122,7 +1122,7 @@ soft_reset:
data[2] = -2;
data[3] = 0;
for (;;) {
- if (sw_get()) {
+ if (switch_get()) {
data[0] = 0x01; // 0x04 is middle, 0x02 is right
} else {
data[0] = 0x00;
diff --git a/stm/usrsw.c b/stm/usrsw.c
index e2565d0e0b..385547843f 100644
--- a/stm/usrsw.c
+++ b/stm/usrsw.c
@@ -12,7 +12,7 @@
#define PYB_USRSW_PORT (GPIOA)
#define PYB_USRSW_PIN (GPIO_Pin_13)
-void sw_init(void) {
+void switch_init(void) {
// make it an input with pull-up
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = PYB_USRSW_PIN;
@@ -45,7 +45,7 @@ void sw_init(void) {
NVIC_Init(&NVIC_InitStructure);
}
-int sw_get(void) {
+int switch_get(void) {
if (PYB_USRSW_PORT->IDR & PYB_USRSW_PIN) {
// pulled high, so switch is not pressed
return 0;
@@ -58,12 +58,12 @@ int sw_get(void) {
/******************************************************************************/
/* Micro Python bindings */
-mp_obj_t pyb_sw(void) {
- if (sw_get()) {
+static mp_obj_t pyb_switch(void) {
+ if (switch_get()) {
return mp_const_true;
} else {
return mp_const_false;
}
}
-
+MP_DEFINE_CONST_FUN_OBJ_0(pyb_switch_obj, pyb_switch);
diff --git a/stm/usrsw.h b/stm/usrsw.h
index 2833baaac7..2da8f069ba 100644
--- a/stm/usrsw.h
+++ b/stm/usrsw.h
@@ -1,7 +1,4 @@
-#ifndef __USRSW_H__
-#define __USRSW_H__
-void sw_init(void);
-int sw_get(void);
+void switch_init(void);
+int switch_get(void);
-mp_obj_t pyb_sw(void);
-#endif //__USRSW_H__
+MP_DECLARE_CONST_FUN_OBJ(pyb_switch_obj);