Skip to content

Commit 8b7f0b4

Browse files
Merge branch 'master' into nrf-rtc
Signed-off-by: RetiredWizard <github@retiredwizard.com>
2 parents 8606964 + d694ac6 commit 8b7f0b4

File tree

35 files changed

+328
-205
lines changed

35 files changed

+328
-205
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@
6565
[submodule "lib/libmetal"]
6666
path = lib/libmetal
6767
url = https://github.com/OpenAMP/libmetal.git
68+
[submodule "lib/arduino-lib"]
69+
path = lib/arduino-lib
70+
url = https://github.com/arduino/arduino-lib-mpy.git

docs/library/machine.RTC.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ Methods
7575
- ``wake`` specifies the sleep mode from where this interrupt can wake
7676
up the system.
7777

78+
.. method:: RTC.memory([data])
79+
80+
``RTC.memory(data)`` will write *data* to the RTC memory, where *data* is any
81+
object which supports the buffer protocol (including `bytes`, `bytearray`,
82+
`memoryview` and `array.array`). ``RTC.memory()`` reads RTC memory and returns
83+
a `bytes` object.
84+
85+
Data written to RTC user memory is persistent across restarts, including
86+
`machine.soft_reset()` and `machine.deepsleep()`.
87+
88+
The maximum length of RTC user memory is 2048 bytes by default on esp32,
89+
and 492 bytes on esp8266.
90+
91+
Availability: esp32, esp8266 ports.
92+
7893
Constants
7994
---------
8095

lib/arduino-lib

Submodule arduino-lib added at 277efd5

ports/esp8266/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ COPT += -Os -DNDEBUG
9696
LDFLAGS += --gc-sections
9797
endif
9898

99+
# Flags for optional C++ source code
100+
CXXFLAGS += $(filter-out -Wmissing-prototypes -Wold-style-definition -std=gnu99,$(CFLAGS))
101+
99102
# Options for mpy-cross
100103
MPY_CROSS_FLAGS += -march=xtensa
101104

ports/nrf/Makefile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ BOARD ?= PCA10040
99
BOARD_DIR ?= boards/$(BOARD)
1010
endif
1111

12-
ifeq ($(wildcard boards/$(BOARD)/.),)
13-
$(error Invalid BOARD specified)
12+
ifeq ($(wildcard $(BOARD_DIR)/.),)
13+
$(error Invalid BOARD specified: $(BOARD_DIR))
1414
endif
1515

1616
# If SoftDevice is selected, try to use that one.
@@ -19,7 +19,7 @@ SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]')
1919

2020
# TODO: Verify that it is a valid target.
2121

22-
include boards/$(BOARD)/mpconfigboard.mk
22+
include $(BOARD_DIR)/mpconfigboard.mk
2323

2424
ifeq ($(SD), )
2525
# If the build directory is not given, make it reflect the board name.
@@ -48,7 +48,7 @@ ifneq ($(LD_FILE),)
4848
LD_FILES = $(LD_FILE)
4949
endif
5050

51-
-include boards/$(BOARD)/modules/boardmodules.mk
51+
-include $(BOARD_DIR)/modules/boardmodules.mk
5252

5353
# qstr definitions (must come before including py.mk)
5454
QSTR_DEFS = qstrdefsport.h
@@ -113,7 +113,7 @@ NRF_DEFINES += -D$(MCU_SUB_VARIANT_UPPER)
113113
NRF_DEFINES += -DCONFIG_GPIO_AS_PINRESET
114114

115115
MAKE_PINS = boards/make-pins.py
116-
BOARD_PINS = boards/$(BOARD)/pins.csv
116+
BOARD_PINS = $(BOARD_DIR)/pins.csv
117117
AF_FILE = $(MCU_VARIANT)_af.csv
118118
PREFIX_FILE = boards/$(MCU_VARIANT)_prefix.c
119119
GEN_PINS_SRC = $(BUILD)/pins_gen.c
@@ -139,7 +139,7 @@ endif
139139
CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
140140
CFLAGS += $(INC) -Wall -Werror -ansi -std=c11 -nostdlib $(COPT) $(NRF_DEFINES) $(CFLAGS_EXTRA)
141141
CFLAGS += -fno-strict-aliasing
142-
CFLAGS += -Iboards/$(BOARD)
142+
CFLAGS += -I$(BOARD_DIR)
143143
CFLAGS += -DNRF5_HAL_H='<$(MCU_VARIANT)_hal.h>'
144144

145145
LDFLAGS += $(CFLAGS)
@@ -163,8 +163,6 @@ CFLAGS += -Os -DNDEBUG
163163
LDFLAGS += -Os
164164
endif
165165

166-
LIBS = \
167-
168166
ifeq ($(MCU_VARIANT), nrf52)
169167

170168
SRC_LIB_C += $(SRC_LIB_LIBM_C)
@@ -482,7 +480,7 @@ $(OBJ): | $(HEADER_BUILD)/pins.h
482480

483481
# Use a pattern rule here so that make will only call make-pins.py once to make
484482
# both pins_gen.c and pins.h
485-
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
483+
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h: $(BOARD_DIR)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
486484
$(ECHO) "Create $@"
487485
$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) --prefix $(PREFIX_FILE) \
488486
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) --output-af-const $(GEN_PINS_AF_CONST)

ports/nrf/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,15 @@ void NORETURN _start(void) {
262262
led_state(1, 0);
263263

264264
#if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN
265-
ret = pyexec_file_if_exists("boot.py");
265+
ret_code = pyexec_file_if_exists("boot.py");
266266
#endif
267267

268268
#if MICROPY_HW_USB_CDC
269269
usb_cdc_init();
270270
#endif
271271

272272
#if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN
273-
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) {
273+
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret_code != 0) {
274274
pyexec_file_if_exists("main.py");
275275
}
276276
#endif

ports/nrf/modules/machine/adc.c

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838

3939
typedef struct _machine_adc_obj_t {
4040
mp_obj_base_t base;
41-
uint8_t id;
42-
#if NRF51
43-
uint8_t ain;
44-
#endif
41+
uint8_t id;
42+
#if NRF51
43+
uint8_t ain;
44+
#endif
4545
} machine_adc_obj_t;
4646

4747
static const machine_adc_obj_t machine_adc_obj[] = {
48-
#if NRF51
48+
#if NRF51
4949
{{&machine_adc_type}, .id = 0, .ain = NRF_ADC_CONFIG_INPUT_0},
5050
{{&machine_adc_type}, .id = 1, .ain = NRF_ADC_CONFIG_INPUT_1},
5151
{{&machine_adc_type}, .id = 2, .ain = NRF_ADC_CONFIG_INPUT_2},
@@ -54,7 +54,7 @@ static const machine_adc_obj_t machine_adc_obj[] = {
5454
{{&machine_adc_type}, .id = 5, .ain = NRF_ADC_CONFIG_INPUT_5},
5555
{{&machine_adc_type}, .id = 6, .ain = NRF_ADC_CONFIG_INPUT_6},
5656
{{&machine_adc_type}, .id = 7, .ain = NRF_ADC_CONFIG_INPUT_7},
57-
#else
57+
#else
5858
{{&machine_adc_type}, .id = 0},
5959
{{&machine_adc_type}, .id = 1},
6060
{{&machine_adc_type}, .id = 2},
@@ -63,14 +63,14 @@ static const machine_adc_obj_t machine_adc_obj[] = {
6363
{{&machine_adc_type}, .id = 5},
6464
{{&machine_adc_type}, .id = 6},
6565
{{&machine_adc_type}, .id = 7},
66-
#endif
66+
#endif
6767
};
6868

6969
void adc_init0(void) {
70-
#if defined(NRF52_SERIES)
70+
#if defined(NRF52_SERIES)
7171
const uint8_t interrupt_priority = 6;
7272
nrfx_saadc_init(interrupt_priority);
73-
#endif
73+
#endif
7474
}
7575

7676
static int adc_find(mp_obj_t id) {
@@ -124,49 +124,49 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
124124
int adc_id = adc_find(args[ARG_id].u_obj);
125125
const machine_adc_obj_t *self = &machine_adc_obj[adc_id];
126126

127-
#if defined(NRF52_SERIES)
127+
#if defined(NRF52_SERIES)
128128
const nrfx_saadc_channel_t config = { \
129129
.channel_config =
130130
{
131131
.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
132132
.resistor_n = NRF_SAADC_RESISTOR_DISABLED,
133-
.gain = NRF_SAADC_GAIN1_4,
134-
.reference = NRF_SAADC_REFERENCE_VDD4,
135-
.acq_time = NRF_SAADC_ACQTIME_3US,
136-
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
137-
.burst = NRF_SAADC_BURST_DISABLED,
133+
.gain = NRF_SAADC_GAIN1_4,
134+
.reference = NRF_SAADC_REFERENCE_VDD4,
135+
.acq_time = NRF_SAADC_ACQTIME_3US,
136+
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
137+
.burst = NRF_SAADC_BURST_DISABLED,
138138
},
139-
.pin_p = (nrf_saadc_input_t)(1 + self->id), // pin_p=0 is AIN0, pin_p=8 is AIN7
140-
.pin_n = NRF_SAADC_INPUT_DISABLED,
141-
.channel_index = self->id,
139+
.pin_p = (nrf_saadc_input_t)(1 + self->id), // pin_p=0 is AIN0, pin_p=8 is AIN7
140+
.pin_n = NRF_SAADC_INPUT_DISABLED,
141+
.channel_index = self->id,
142142
};
143143
nrfx_saadc_channels_config(&config, 1);
144-
#endif
144+
#endif
145145

146146
return MP_OBJ_FROM_PTR(self);
147147
}
148148

149-
int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj) {
149+
int16_t machine_adc_value_read(machine_adc_obj_t *adc_obj) {
150150

151-
#if NRF51
151+
#if NRF51
152152
nrf_adc_value_t value = 0;
153153

154154
nrfx_adc_channel_t channel_config = {
155155
.config.resolution = NRF_ADC_CONFIG_RES_8BIT,
156-
.config.input = NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS,
157-
.config.reference = NRF_ADC_CONFIG_REF_VBG,
158-
.config.input = adc_obj->ain,
159-
.config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
156+
.config.input = NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS,
157+
.config.reference = NRF_ADC_CONFIG_REF_VBG,
158+
.config.input = adc_obj->ain,
159+
.config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
160160
};
161161

162162
nrfx_adc_sample_convert(&channel_config, &value);
163-
#else // NRF52
163+
#else // NRF52
164164
nrf_saadc_value_t value = 0;
165165

166166
nrfx_saadc_simple_mode_set((1 << adc_obj->id), NRF_SAADC_RESOLUTION_8BIT, NRF_SAADC_INPUT_DISABLED, NULL);
167167
nrfx_saadc_buffer_set(&value, 1);
168168
nrfx_saadc_mode_trigger();
169-
#endif
169+
#endif
170170
return value;
171171
}
172172

@@ -209,10 +209,9 @@ static MP_DEFINE_CONST_FUN_OBJ_1(mp_machine_adc_value_obj, machine_adc_value);
209209
#define DIODE_VOLT_DROP_MILLIVOLT (270) // Voltage drop over diode.
210210

211211
#define BATTERY_MILLIVOLT(VALUE) \
212-
((((VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLT) / 255) * ADC_PRE_SCALING_MULTIPLIER)
212+
((((VALUE)*ADC_REF_VOLTAGE_IN_MILLIVOLT) / 255) * ADC_PRE_SCALING_MULTIPLIER)
213213

214-
static uint8_t battery_level_in_percent(const uint16_t mvolts)
215-
{
214+
static uint8_t battery_level_in_percent(const uint16_t mvolts) {
216215
uint8_t battery_level;
217216

218217
if (mvolts >= 3000) {
@@ -236,42 +235,42 @@ static uint8_t battery_level_in_percent(const uint16_t mvolts)
236235
/// Get battery level in percentage.
237236
mp_obj_t machine_adc_battery_level(void) {
238237

239-
#if NRF51
238+
#if NRF51
240239
nrf_adc_value_t value = 0;
241240

242241
nrfx_adc_channel_t channel_config = {
243242
.config.resolution = NRF_ADC_CONFIG_RES_8BIT,
244-
.config.input = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD,
245-
.config.reference = NRF_ADC_CONFIG_REF_VBG,
246-
.config.input = NRF_ADC_CONFIG_INPUT_DISABLED,
247-
.config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
243+
.config.input = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD,
244+
.config.reference = NRF_ADC_CONFIG_REF_VBG,
245+
.config.input = NRF_ADC_CONFIG_INPUT_DISABLED,
246+
.config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
248247
};
249248

250249
nrfx_adc_sample_convert(&channel_config, &value);
251-
#else // NRF52
250+
#else // NRF52
252251
nrf_saadc_value_t value = 0;
253252

254253
const nrfx_saadc_channel_t config = { \
255254
.channel_config =
256255
{
257256
.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
258257
.resistor_n = NRF_SAADC_RESISTOR_DISABLED,
259-
.gain = NRF_SAADC_GAIN1_6,
260-
.reference = NRF_SAADC_REFERENCE_INTERNAL,
261-
.acq_time = NRF_SAADC_ACQTIME_3US,
262-
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
263-
.burst = NRF_SAADC_BURST_DISABLED,
258+
.gain = NRF_SAADC_GAIN1_6,
259+
.reference = NRF_SAADC_REFERENCE_INTERNAL,
260+
.acq_time = NRF_SAADC_ACQTIME_3US,
261+
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
262+
.burst = NRF_SAADC_BURST_DISABLED,
264263
},
265-
.pin_p = NRF_SAADC_INPUT_VDD,
266-
.pin_n = NRF_SAADC_INPUT_DISABLED,
267-
.channel_index = 0,
264+
.pin_p = NRF_SAADC_INPUT_VDD,
265+
.pin_n = NRF_SAADC_INPUT_DISABLED,
266+
.channel_index = 0,
268267
};
269268
nrfx_saadc_channels_config(&config, 1);
270269

271270
nrfx_saadc_simple_mode_set((1 << 0), NRF_SAADC_RESOLUTION_8BIT, NRF_SAADC_INPUT_DISABLED, NULL);
272271
nrfx_saadc_buffer_set(&value, 1);
273272
nrfx_saadc_mode_trigger();
274-
#endif
273+
#endif
275274

276275
uint16_t batt_lvl_in_milli_volts = BATTERY_MILLIVOLT(value) + DIODE_VOLT_DROP_MILLIVOLT;
277276
uint16_t batt_in_percent = battery_level_in_percent(batt_lvl_in_milli_volts);

ports/nrf/modules/machine/adc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ typedef struct _machine_adc_obj_t machine_adc_obj_t;
3131

3232
void adc_init0(void);
3333

34-
int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj);
34+
int16_t machine_adc_value_read(machine_adc_obj_t *adc_obj);
3535

3636
#endif // ADC_H__

ports/nrf/modules/machine/i2c.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
typedef struct _machine_hard_i2c_obj_t {
7070
mp_obj_base_t base;
71-
nrfx_twi_t p_twi; // Driver instance
71+
nrfx_twi_t p_twi; // Driver instance
7272
} machine_hard_i2c_obj_t;
7373

7474
static const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = {
@@ -159,8 +159,7 @@ int machine_hard_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size
159159
if (err_code != NRFX_SUCCESS) {
160160
if (err_code == NRFX_ERROR_DRV_TWI_ERR_ANACK) {
161161
return -MP_ENODEV;
162-
}
163-
else if (err_code == NRFX_ERROR_DRV_TWI_ERR_DNACK) {
162+
} else if (err_code == NRFX_ERROR_DRV_TWI_ERR_DNACK) {
164163
return -MP_EIO;
165164
}
166165
return -MP_ETIMEDOUT;

ports/nrf/modules/machine/modmachine.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ void machine_init(void) {
122122
reset_cause = PYB_RESET_LOCKUP;
123123
} else if (state & POWER_RESETREAS_OFF_Msk) {
124124
reset_cause = PYB_RESET_POWER_ON;
125-
#if !defined(NRF9160_XXAA)
125+
#if !defined(NRF9160_XXAA)
126126
} else if (state & POWER_RESETREAS_LPCOMP_Msk) {
127127
reset_cause = PYB_RESET_LPCOMP;
128-
#endif
128+
#endif
129129
} else if (state & POWER_RESETREAS_DIF_Msk) {
130130
reset_cause = PYB_RESET_DIF;
131-
#if defined(NRF52_SERIES)
131+
#if defined(NRF52_SERIES)
132132
} else if (state & POWER_RESETREAS_NFC_Msk) {
133133
reset_cause = PYB_RESET_NFC;
134-
#endif
134+
#endif
135135
}
136136

137137
// clear reset reason
@@ -222,22 +222,22 @@ static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
222222
}
223223

224224
static mp_obj_t machine_enable_irq(void) {
225-
#ifndef BLUETOOTH_SD
225+
#ifndef BLUETOOTH_SD
226226
__enable_irq();
227-
#else
227+
#else
228228

229-
#endif
229+
#endif
230230
return mp_const_none;
231231
}
232232
MP_DEFINE_CONST_FUN_OBJ_0(machine_enable_irq_obj, machine_enable_irq);
233233

234234
// Resets the board in a manner similar to pushing the external RESET button.
235235
static mp_obj_t machine_disable_irq(void) {
236-
#ifndef BLUETOOTH_SD
236+
#ifndef BLUETOOTH_SD
237237
__disable_irq();
238-
#else
238+
#else
239239

240-
#endif
240+
#endif
241241
return mp_const_none;
242242
}
243243
MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy