Skip to content

Commit 0071552

Browse files
authored
Merge pull request adafruit#969 from arturo182/nrf_more_commonhal
nrf: Rewrite more common-hal with nrfx and sync with atsamd port
2 parents 039b4dc + b87bba8 commit 0071552

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

ports/nrf/common-hal/board/__init__.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,5 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include <string.h>
28-
29-
#include "py/runtime.h"
30-
#include "py/mphal.h"
31-
#include "common-hal/microcontroller/Pin.h"
32-
3327
// Pins aren't actually defined here. They are in the board specific directory
34-
// such as boards/arduino_zero/pins.c.
28+
// such as boards/feather52832/pins.csv

ports/nrf/common-hal/microcontroller/__init__.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
#include "common-hal/microcontroller/Pin.h"
2828
#include "common-hal/microcontroller/Processor.h"
2929

30-
3130
#include "shared-bindings/microcontroller/__init__.h"
3231
#include "shared-bindings/microcontroller/Pin.h"
3332
#include "shared-bindings/microcontroller/Processor.h"
3433

35-
// TODO porting common_hal_mcu
34+
#include "supervisor/filesystem.h"
35+
#include "nrfx_glue.h"
36+
3637
void common_hal_mcu_delay_us(uint32_t delay) {
37-
// os_delay_us(delay);
38+
NRFX_DELAY_US(delay);
3839
}
3940

4041
void common_hal_mcu_disable_interrupts() {
@@ -48,7 +49,8 @@ void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
4849
}
4950

5051
void common_hal_mcu_reset(void) {
51-
// TODO: see atmel-samd for functionality
52+
filesystem_flush();
53+
NVIC_SystemReset();
5254
}
5355

5456
// The singleton microcontroller.Processor object, bound to microcontroller.cpu

ports/nrf/common-hal/storage/__init__.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@
2828

2929
#include "py/mperrno.h"
3030
#include "py/runtime.h"
31+
#include "shared-bindings/microcontroller/__init__.h"
3132
#include "shared-bindings/storage/__init__.h"
33+
#include "supervisor/filesystem.h"
3234

3335
extern volatile bool mp_msc_enabled;
3436

35-
void common_hal_storage_remount(const char* mount_path, bool readonly) {
36-
if (strcmp(mount_path, "/") != 0) {
37+
void common_hal_storage_remount(const char *mount_path, bool readonly) {
38+
if (strcmp(mount_path, "/") != 0)
3739
mp_raise_OSError(MP_EINVAL);
38-
}
3940
}
4041

41-
void common_hal_storage_erase_filesystem() {
42-
mp_raise_NotImplementedError("");
42+
void common_hal_storage_erase_filesystem(void) {
43+
filesystem_init(false, true); // Force a re-format.
44+
common_hal_mcu_reset();
45+
// We won't actually get here, since we're resetting.
4346
}

ports/nrf/common-hal/time/__init__.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
#include "shared-bindings/time/__init__.h"
3030
#include "tick.h"
3131

32-
inline uint64_t common_hal_time_monotonic() {
33-
return ticks_ms;
32+
#include "nrfx_glue.h"
33+
34+
inline uint64_t common_hal_time_monotonic(void) {
35+
return ticks_ms;
3436
}
3537

3638
void common_hal_time_delay_ms(uint32_t delay) {
37-
mp_hal_delay_ms(delay);
39+
NRFX_DELAY_US(delay);
3840
}

ports/nrf/nrfx_glue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
extern "C" {
4646
#endif
4747

48+
#include <drivers/nrfx_common.h>
49+
4850
/**
4951
* @defgroup nrfx_glue nrfx_glue.h
5052
* @{

0 commit comments

Comments
 (0)