8000 nrf: Move pyb module to boards module · andrewleech/micropython@6011441 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6011441

Browse files
glennrubdpgeorge
authored andcommitted
nrf: Move pyb module to boards module
Cleaning up use of "pyb" module. Moving the file to a new folder and updating the makefile accordingly. New module created called "board" to take over the functionality of the legacy "pyb" module. Updating outdated documentation referring to pyb.Pin, to now point to machine.Pin.
1 parent 4a323f8 commit 6011441

File tree

15 files changed

+101
-104
lines changed

15 files changed

+101
-104
lines changed

ports/nrf/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ INC += -I./modules/ubluepy
5757
INC += -I./modules/music
5858
INC += -I./modules/random
5959
INC += -I./modules/ble
60+
INC += -I./modules/board
6061
INC += -I../../lib/mp-readline
6162
INC += -I./drivers/bluetooth
6263
INC += -I./drivers
@@ -203,12 +204,12 @@ DRIVERS_SRC_C += $(addprefix modules/,\
203204
machine/timer.c \
204205
machine/rtcounter.c \
205206
machine/pwm.c \
206-
machine/led.c \
207207
machine/temp.c \
208208
uos/moduos.c \
209209
uos/microbitfs.c \
210210
utime/modutime.c \
211-
pyb/modpyb.c \
211+
board/modboard.c \
212+
board/led.c \
212213
ubluepy/modubluepy.c \
213214
ubluepy/ubluepy_peripheral.c \
214215
ubluepy/ubluepy_service.c \

ports/nrf/examples/ubluepy_temp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
# THE SOFTWARE
2424

25-
from pyb import LED
25+
from board import LED
2626
from machine import RTCounter, Temp
2727
from ubluepy import Service, Characteristic, UUID, Peripheral, constants
2828

ports/nrf/help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2013, 2014 Damien P. George
7-
* Copyright (c) 2016 Glenn Ruben Bakke
7+
* Copyright (c) 2016 - 2018 Glenn Ruben Bakke
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* of this software and associated documentation files (the "Software"), to deal
@@ -38,7 +38,7 @@ const char nrf5_help_text[] =
3838
"\n"
3939
"Quick overview of commands for the board:\n"
4040
#if MICROPY_HW_HAS_LED
41-
" pyb.LED(n) -- create an LED object for LED n (n=" HELP_TEXT_BOARD_LED ")\n"
41+
" board.LED(n) -- create an LED object for LED n (n=" HELP_TEXT_BOARD_LED ")\n"
4242
"\n"
4343
#endif
4444
#if BLUETOOTH_SD

ports/nrf/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int main(int argc, char **argv) {
149149
MP_OBJ_NEW_SMALL_INT(0),
150150
MP_OBJ_NEW_SMALL_INT(115200),
151151
};
152-
MP_STATE_PORT(pyb_stdio_uart) = machine_hard_uart_type.make_new((mp_obj_t)&machine_hard_uart_type, MP_ARRAY_SIZE(args), 0, args);
152+
MP_STATE_PORT(board_stdio_uart) = machine_hard_uart_type.make_new((mp_obj_t)&machine_hard_uart_type, MP_ARRAY_SIZE(args), 0, args);
153153
}
154154
#endif
155155

@@ -195,8 +195,8 @@ pin_init0();
195195
#if (MICROPY_HW_HAS_LED)
196196
led_init();
197197

198-
do_str("import pyb\r\n" \
199-
"pyb.LED(1).on()",
198+
do_str("import board\r\n" \
199+
"board.LED(1).on()",
200200
MP_PARSE_FILE_INPUT);
201201
#endif
202202

ports/nrf/modules/machine/led.c renamed to ports/nrf/modules/board/led.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2013-2016 Damien P. George
7-
* Copyright (c) 2015 Glenn Ruben Bakke
7+
* Copyright (c) 2015 - 2018 Glenn Ruben Bakke
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* of this software and associated documentation files (the "Software"), to deal
@@ -36,49 +36,49 @@
3636
#define LED_OFF(pin) {(MICROPY_HW_LED_PULLUP) ? nrf_gpio_pin_set(pin) : nrf_gpio_pin_clear(pin); }
3737
#define LED_ON(pin) {(MICROPY_HW_LED_PULLUP) ? nrf_gpio_pin_clear(pin) : nrf_gpio_pin_set(pin); }
3838

39-
typedef struct _pyb_led_obj_t {
39+
typedef struct _board_led_obj_t {
4040
mp_obj_base_t base;
4141
mp_uint_t led_id;
4242
mp_uint_t hw_pin;
4343
uint8_t hw_pin_port;
44-
} pyb_led_obj_t;
44+
} board_led_obj_t;
4545

46-
STATIC const pyb_led_obj_t pyb_led_obj[] = {
46+
STATIC const board_led_obj_t board_led_obj[] = {
4747
#if MICROPY_HW_LED_TRICOLOR
48-
{{&pyb_led_type}, PYB_LED_RED, MICROPY_HW_LED_RED},
49-
{{&pyb_led_type}, PYB_LED_GREEN, MICROPY_HW_LED_GREEN},
50-
{{&pyb_led_type}, PYB_LED_BLUE, MICROPY_HW_LED_BLUE},
48+
{{&board_led_type}, BOARD_LED_RED, MICROPY_HW_LED_RED},
49+
{{&board_led_type}, BOARD_LED_GREEN, MICROPY_HW_LED_GREEN},
50+
{{&board_led_type}, BOARD_LED_BLUE, MICROPY_HW_LED_BLUE},
5151
#elif (MICROPY_HW_LED_COUNT == 1)
52-
{{&pyb_led_type}, PYB_LED1, MICROPY_HW_LED1},
52+
{{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1},
5353
#elif (MICROPY_HW_LED_COUNT == 2)
54-
{{&pyb_led_type}, PYB_LED1, MICROPY_HW_LED1},
55-
{{&pyb_led_type}, PYB_LED2, MICROPY_HW_LED2},
54+
{{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1},
55+
{{&board_led_type}, BOARD_LED2, MICROPY_HW_LED2},
5656
#else
57-
{{&pyb_led_type}, PYB_LED1, MICROPY_HW_LED1},
58-
{{&pyb_led_type}, PYB_LED2, MICROPY_HW_LED2},
59-
{{&pyb_led_type}, PYB_LED3, MICROPY_HW_LED3},
60-
{{&pyb_led_type}, PYB_LED4, MICROPY_HW_LED4},
57+
{{&board_led_type}, BOARD_LED1, MICROPY_HW_LED1},
58+
{{&board_led_type}, BOARD_LED2, MICROPY_HW_LED2},
59+
{{&board_led_type}, BOARD_LED3, MICROPY_HW_LED3},
60+
{{&board_led_type}, BOARD_LED4, MICROPY_HW_LED4},
6161
#endif
6262
};
6363

64-
#define NUM_LEDS MP_ARRAY_SIZE(pyb_led_obj)
64+
#define NUM_LEDS MP_ARRAY_SIZE(board_led_obj)
6565

6666
void led_init(void) {
6767
for (uint8_t i = 0; i < NUM_LEDS; i++) {
68-
LED_OFF(pyb_led_obj[i].hw_pin);
69-
nrf_gpio_cfg_output(pyb_led_obj[i].hw_pin);
68+
LED_OFF(board_led_obj[i].hw_pin);
69+
nrf_gpio_cfg_output(board_led_obj[i].hw_pin);
7070
}
7171
}
7272

73-
void led_state(pyb_led_obj_t * led_obj, int state) {
73+
void led_state(board_led_obj_t * led_obj, int state) {
7474
if (state == 1) {
7575
LED_ON(led_obj->hw_pin);
7676
} else {
7777
LED_OFF(led_obj->hw_pin);
7878
}
7979
}
8080

81-
void led_toggle(pyb_led_obj_t * led_obj) {
81+
void led_toggle(board_led_obj_t * led_obj) {
8282
nrf_gpio_pin_toggle(led_obj->hw_pin);
8383
}
8484

@@ -88,7 +88,7 @@ void led_toggle(pyb_led_obj_t * led_obj) {
8888
/* MicroPython bindings */
8989

9090
void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
91-
pyb_led_obj_t *self = self_in;
91+
board_led_obj_t *self = self_in;
9292
mp_printf(print, "LED(%lu)", self->led_id);
9393
}
9494

@@ -109,29 +109,29 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_
109109
}
110110

111111
// return static led object
112-
return (mp_obj_t)&pyb_led_obj[led_id - 1];
112+
return (mp_obj_t)&board_led_obj[led_id - 1];
113113
}
114114

115115
/// \method on()
116116
/// Turn the LED on.
117117
mp_obj_t led_obj_on(mp_obj_t self_in) {
118-
pyb_led_obj_t *self = self_in;
118+
board_led_obj_t *self = self_in;
119119
led_state(self, 1);
120120
return mp_const_none;
121121
}
122122

123123
/// \method off()
124124
/// Turn the LED off.
125125
mp_obj_t led_obj_off(mp_obj_t self_in) {
126-
pyb_led_obj_t *self = self_in;
126+
board_led_obj_t *self = self_in;
127127
led_state(self, 0);
128128
return mp_const_none;
129129
}
130130

131131
/// \method toggle()
132132
/// Toggle the LED between on and off.
133133
mp_obj_t led_obj_toggle(mp_obj_t self_in) {
134-
pyb_led_obj_t *self = self_in;
134+
board_led_obj_t *self = self_in;
135135
led_toggle(self);
136136
return mp_const_none;
137137
}
@@ -148,7 +148,7 @@ STATIC const mp_rom_map_elem_t led_locals_dict_table[] = {
148148

149149
STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table);
150150

151-
const mp_obj_type_t pyb_led_type = {
151+
const mp_obj_type_t board_led_type = {
152152
{ &mp_type_type },
153153
.name = MP_QSTR_LED,
154154
.print = led_obj_print,

ports/nrf/modules/mac 10000 hine/led.h renamed to ports/nrf/modules/board/led.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2013, 2014 Damien P. George
7-
* Copyright (c) 2015 Glenn Ruben Bakke
7+
* Copyright (c) 2015 - 2018 Glenn Ruben Bakke
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* of this software and associated documentation files (the "Software"), to deal
@@ -30,24 +30,24 @@
3030

3131
typedef enum {
3232
#if MICROPY_HW_LED_TRICOLOR
33-
PYB_LED_RED = 1,
34-
PYB_LED_GREEN = 2,
35-
PYB_LED_BLUE = 3
33+
BOARD_LED_RED = 1,
34+
BOARD_LED_GREEN = 2,
35+
BOARD_LED_BLUE = 3
3636
#elif (MICROPY_HW_LED_COUNT == 1)
37-
PYB_LED1 = 1,
37+
BOARD_LED1 = 1,
3838
#elif (MICROPY_HW_LED_COUNT == 2)
39-
PYB_LED1 = 1,
40-
PYB_LED2 = 2,
39+
BOARD_LED1 = 1,
40+
BOARD_LED2 = 2,
4141
#else
42-
PYB_LED1 = 1,
43-
PYB_LED2 = 2,
44-
PYB_LED3 = 3,
45-
PYB_LED4 = 4
42+
BOARD_LED1 = 1,
43+
BOARD_LED2 = 2,
44+
BOARD_LED3 = 3,
45+
BOARD_LED4 = 4
4646
#endif
47-
} pyb_led_t;
47+
} board_led_t;
4848

4949
void led_init(void);
5050

51-
extern const mp_obj_type_t pyb_led_type;
51+
extern const mp_obj_type_t board_led_type;
5252

5353
#endif // LED_H

ports/nrf/modules/pyb/modpyb.c renamed to ports/nrf/modules/board/modboard.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2015 Glenn Ruben Bakke
6+
* Copyright (c) 2015 - 2018 Glenn Ruben Bakke
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -33,23 +33,21 @@
3333
#include "pin.h"
3434

3535
#if MICROPY_HW_HAS_LED
36-
#define PYB_LED_MODULE { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pyb_led_type) },
36+
#define PYB_LED_MODULE { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&board_led_type) },
3737
#else
3838
#define PYB_LED_MODULE
3939
#endif
4040

41-
STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
42-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) },
41+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
42+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_board) },
4343
{ MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) },
44-
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) },
4544
PYB_LED_MODULE
46-
/* { MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&pyb_main_obj) }*/
4745
};
4846

4947

50-
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
48+
STATIC MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
5149

52-
const mp_obj_module_t pyb_module = {
50+
const mp_obj_module_t board_module = {
5351
.base = { &mp_type_module },
54-
.globals = (mp_obj_dict_t*)&pyb_module_globals,
52+
.globals = (mp_obj_dict_t*)&board_module_globals,
5553
};

ports/nrf/modules/machine/modmachine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) {
136136
}
137137
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
138138

139-
// Resets the pyboard in a manner similar to pushing the external RESET button.
139+
// Resets the board in a manner similar to pushing the external RESET button.
140140
STATIC mp_obj_t machine_reset(void) {
141141
NVIC_SystemReset();
142142
return mp_const_none;
@@ -176,7 +176,7 @@ STATIC mp_obj_t machine_enable_irq(void) {
176176
}
177177
MP_DEFINE_CONST_FUN_OBJ_0(machine_enable_irq_obj, machine_enable_irq);
178178

179-
// Resets the pyboard in a manner similar to pushing the external RESET button.
179+
// Resets the board in a manner similar to pushing the external RESET button.
180180
STATIC mp_obj_t machine_disable_irq(void) {
181181
#ifndef BLUETOOTH_SD
182182
__disable_irq();
@@ -195,7 +195,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
195195
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
196196
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
197197
#if MICROPY_HW_ENABLE_RNG
198-
{ MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&pyb_rng_get_obj) },
198+
{ MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&random_module) },
199199
#endif
200200
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_sleep_obj) },
201201
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) },

0 commit comments

Comments
 (0)
0