Skip to content

Commit 823877b

Browse files
committed
stm: rename sw_xx to switch_xx; change Python bindings to new version.
1 parent cd3c1ee commit 823877b

3 files changed

Lines changed: 13 additions & 16 deletions

File tree

stm/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ int main(void) {
773773
led_state(PYB_LED_G1, 1);
774774

775775
// more sub-system init
776-
sw_init();
776+
switch_init();
777777
storage_init();
778778

779779
//usart_init(); disabled while wi-fi is enabled
@@ -822,7 +822,7 @@ int main(void) {
822822
rt_store_attr(m, qstr_from_str_static("gc"), rt_make_function_0(pyb_gc));
823823
rt_store_attr(m, qstr_from_str_static("delay"), rt_make_function_1(pyb_delay));
824824
rt_store_attr(m, qstr_from_str_static("led"), rt_make_function_1(pyb_led));
825-
rt_store_attr(m, qstr_from_str_static("switch"), rt_make_function_0(pyb_sw));
825+
rt_store_attr(m, qstr_from_str_static("switch"), (mp_obj_t)&pyb_switch_obj);
826826
rt_store_attr(m, qstr_from_str_static("servo"), rt_make_function_2(pyb_servo_set));
827827
rt_store_attr(m, qstr_from_str_static("pwm"), rt_make_function_2(pyb_pwm_set));
828828
rt_store_attr(m, qstr_from_str_static("accel"), (mp_obj_t)&pyb_mma_read_obj);
@@ -848,10 +848,10 @@ int main(void) {
848848

849849
// check if user switch held (initiates reset of filesystem)
850850
bool reset_filesystem = false;
851-
if (sw_get()) {
851+
if (switch_get()) {
852852
reset_filesystem = true;
853853
for (int i = 0; i < 50; i++) {
854-
if (!sw_get()) {
854+
if (!switch_get()) {
855855
reset_filesystem = false;
856856
break;
857857
}
@@ -1122,7 +1122,7 @@ int main(void) {
11221122
data[2] = -2;
11231123
data[3] = 0;
11241124
for (;;) {
1125-
if (sw_get()) {
1125+
if (switch_get()) {
11261126
data[0] = 0x01; // 0x04 is middle, 0x02 is right
11271127
} else {
11281128
data[0] = 0x00;

stm/usrsw.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define PYB_USRSW_PORT (GPIOA)
1313
#define PYB_USRSW_PIN (GPIO_Pin_13)
1414

15-
void sw_init(void) {
15+
void switch_init(void) {
1616
// make it an input with pull-up
1717
GPIO_InitTypeDef GPIO_InitStructure;
1818
GPIO_InitStructure.GPIO_Pin = PYB_USRSW_PIN;
@@ -45,7 +45,7 @@ void sw_init(void) {
4545
NVIC_Init(&NVIC_InitStructure);
4646
}
4747

48-
int sw_get(void) {
48+
int switch_get(void) {
4949
if (PYB_USRSW_PORT->IDR & PYB_USRSW_PIN) {
5050
// pulled high, so switch is not pressed
5151
return 0;
@@ -58,12 +58,12 @@ int sw_get(void) {
5858
/******************************************************************************/
5959
/* Micro Python bindings */
6060

61-
mp_obj_t pyb_sw(void) {
62-
if (sw_get()) {
61+
static mp_obj_t pyb_switch(void) {
62+
if (switch_get()) {
6363
return mp_const_true;
6464
} else {
6565
return mp_const_false;
6666
}
6767
}
6868

69-
69+
MP_DEFINE_CONST_FUN_OBJ_0(pyb_switch_obj, pyb_switch);

stm/usrsw.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#ifndef __USRSW_H__
2-
#define __USRSW_H__
3-
void sw_init(void);
4-
int sw_get(void);
1+
void switch_init(void);
2+
int switch_get(void);
53

6-
mp_obj_t pyb_sw(void);
7-
#endif //__USRSW_H__
4+
MP_DECLARE_CONST_FUN_OBJ(pyb_switch_obj);

0 commit comments

Comments
 (0)