Skip to content

Commit a53b1c7

Browse files
committed
code format
1 parent ce01496 commit a53b1c7

File tree

10 files changed

+71
-363
lines changed

10 files changed

+71
-363
lines changed

ports/nrf/Makefile

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ SRC_C += \
107107
fatfs_port.c \
108108
fifo.c \
109109
tick.c \
110+
background.c \
111+
internal_flash.c \
110112
drivers/softpwm.c \
111113
drivers/ticker.c \
112114
drivers/bluetooth/ble_drv.c \
@@ -115,7 +117,6 @@ SRC_C += \
115117
nrfx/mdk/system_$(MCU_SUB_VARIANT).c \
116118
nrfx/hal/nrf_nvmc.c \
117119
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
118-
background.c \
119120
lib/oofatfs/ff.c \
120121
lib/oofatfs/option/ccsbcs.c \
121122
lib/timeutils/timeutils.c \
@@ -126,25 +127,23 @@ SRC_C += \
126127
lib/utils/stdout_helpers.c \
127128
lib/libc/string0.c \
128129
lib/mp-readline/readline.c \
129-
internal_flash.c \
130130

131131
ifeq ($(MCU_SUB_VARIANT),nrf52840)
132132

133133
SRC_C += \
134134
usb/tusb_descriptors.c \
135135
usb/usb_msc_flash.c \
136-
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
137-
lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \
138-
lib/tinyusb/src/common/tusb_fifo.c \
139-
lib/tinyusb/src/device/usbd.c \
140-
lib/tinyusb/src/device/usbd_desc.c \
141-
lib/tinyusb/src/class/msc/msc_device.c \
142-
lib/tinyusb/src/class/cdc/cdc_device.c \
143-
lib/tinyusb/src/tusb.c \
136+
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
137+
lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \
138+
lib/tinyusb/src/common/tusb_fifo.c \
139+
lib/tinyusb/src/device/usbd.c \
140+
lib/tinyusb/src/device/usbd_desc.c \
141+
lib/tinyusb/src/class/msc/msc_device.c \
142+
lib/tinyusb/src/class/cdc/cdc_device.c \
143+
lib/tinyusb/src/tusb.c \
144144

145145
endif
146146

147-
148147
DRIVERS_SRC_C += $(addprefix modules/,\
149148
ubluepy/modubluepy.c \
150149
ubluepy/ubluepy_peripheral.c \
@@ -264,7 +263,6 @@ hex: $(BUILD)/$(OUTPUT_FILENAME).hex
264263
$(BUILD)/$(OUTPUT_FILENAME).hex: $(BUILD)/$(OUTPUT_FILENAME).elf
265264
$(OBJCOPY) -O ihex $< $@
266265

267-
268266
#####################
269267
# Flash with debugger
270268
#####################
@@ -300,7 +298,6 @@ sd: $(BUILD)/$(OUTPUT_FILENAME).hex
300298

301299
endif
302300

303-
304301
#####################
305302
# Flash with DFU
306303
#####################
@@ -312,7 +309,6 @@ else
312309
NRFUTIL = nrfutil
313310
endif
314311

315-
316312
check_defined = \
317313
$(strip $(foreach 1,$1, \
318314
$(call __check_defined,$1,$(strip $(value 2)))))
@@ -335,8 +331,6 @@ uf2: $(BUILD)/$(OUTPUT_FILENAME).hex
335331
$(ECHO) "Create $(OUTPUT_FILENAME).uf2"
336332
$(PYTHON2) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/$(OUTPUT_FILENAME).uf2" $^
337333

338-
339-
340334
$(BUILD)/dfu-package.zip: dfu-gen
341335

342336
$(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)

ports/nrf/background.c

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
1-
/**************************************************************************/
2-
/*!
3-
@file background.c
4-
@author hathach (tinyusb.org)
5-
6-
@section LICENSE
7-
8-
Software License Agreement (BSD License)
9-
10-
Copyright (c) 2018, Adafruit Industries (adafruit.com)
11-
All rights reserved.
12-
13-
Redistribution and use in source and binary forms, with or without
14-
modification, are permitted provided that the following conditions are met:
15-
1. Redistributions of source code must retain the above copyright
16-
notice, this list of conditions and the following disclaimer.
17-
2. Redistributions in binary form must reproduce the above copyright
18-
notice, this list of conditions and the following disclaimer in the
19-
documentation and/or other materials provided with the distribution.
20-
3. Neither the name of the copyright holders nor the
21-
names of its contributors may be used to endorse or promote products
22-
derived from this software without specific prior written permission.
23-
24-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25-
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28-
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34-
*/
35-
/**************************************************************************/
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
3626

3727
#include "tusb.h"
3828

39-
4029
void run_background_tasks(void) {
41-
4230
#ifdef NRF52840_XXAA
4331
tusb_task();
4432
tud_cdc_flush();

ports/nrf/boards/pca10056/board.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ void tud_umount_cb(uint8_t rhport) {
8383
(void) rhport;
8484
}
8585

86-
uint32_t tusb_hal_millis(void)
87-
{
86+
uint32_t tusb_hal_millis(void) {
8887
uint64_t ms;
8988
uint32_t us;
9089
current_tick(&ms, &us);

ports/nrf/boards/pca10056/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#define PORT_HEAP_SIZE (128 * 1024)
3636
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
3737

38-
3938
// Temp (could be removed) 0: usb cdc (default), 1 : hwuart (jlink)
4039
#define CFG_HWUART_FOR_SERIAL 0
4140

ports/nrf/drivers/bluetooth/ble_uart.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434

3535
#if MICROPY_PY_BLE_NUS
3636

37-
#if BLUETOOTH_WEBBLUETOOTH_REPL
38-
//#include "hal_time.h"
39-
#endif // BLUETOOTH_WEBBLUETOOTH_REPL
40-
4137
static ubluepy_uuid_obj_t uuid_obj_service = {
4238
.base.type = &ubluepy_uuid_type,
4339
.type = UBLUEPY_UUID_128_BIT,

ports/nrf/internal_flash.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,15 @@
4242
#include "nrf_sdm.h"
4343
#endif
4444

45-
/*------------------------------------------------------------------*/
46-
/* VARIABLES
47-
*------------------------------------------------------------------*/
48-
4945
// defined in linker
5046
extern uint32_t __fatfs_flash_start_addr[];
5147
extern uint32_t __fatfs_flash_length[];
5248

53-
#define NO_CACHE 0xffffffff
54-
#define FL_PAGE_SZ 4096
49+
#define NO_CACHE 0xffffffff
50+
#define FL_PAGE_SZ 4096
5551

56-
uint8_t _fl_cache[FL_PAGE_SZ] __attribute__((aligned(4)));
57-
uint32_t _fl_pg_addr = NO_CACHE;
52+
uint8_t _flash_cache[FL_PAGE_SZ] __attribute__((aligned(4)));
53+
uint32_t _flash_page_addr = NO_CACHE;
5854

5955

6056
/*------------------------------------------------------------------*/
@@ -66,14 +62,14 @@ static inline uint32_t lba2addr(uint32_t block) {
6662

6763
void internal_flash_init(void) {
6864
// Activity LED for flash writes.
69-
#ifdef MICROPY_HW_LED_MSC
70-
struct port_config pin_conf;
71-
port_get_config_defaults(&pin_conf);
72-
73-
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
74-
port_pin_set_config(MICROPY_HW_LED_MSC, &pin_conf);
75-
port_pin_set_output_level(MICROPY_HW_LED_MSC, false);
76-
#endif
65+
#ifdef MICROPY_HW_LED_MSC
66+
struct port_config pin_conf;
67+
port_get_config_defaults(&pin_conf);
68+
69+
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
70+
port_pin_set_config(MICROPY_HW_LED_MSC, &pin_conf);
71+
port_pin_set_output_level(MICROPY_HW_LED_MSC, false);
72+
#endif
7773
}
7874

7975
uint32_t internal_flash_get_block_size(void) {
@@ -86,16 +82,16 @@ uint32_t internal_flash_get_block_count(void) {
8682

8783
// TODO support flashing with SD enabled
8884
void internal_flash_flush(void) {
89-
if (_fl_pg_addr == NO_CACHE) return;
85+
if (_flash_page_addr == NO_CACHE) return;
9086

9187
// Skip if data is the same
92-
if (memcmp(_fl_cache, (void *)_fl_pg_addr, FL_PAGE_SZ) != 0) {
88+
if (memcmp(_flash_cache, (void *)_flash_page_addr, FL_PAGE_SZ) != 0) {
9389
// _is_flashing = true;
94-
nrf_nvmc_page_erase(_fl_pg_addr);
95-
nrf_nvmc_write_words(_fl_pg_addr, (uint32_t *)_fl_cache, FL_PAGE_SZ / sizeof(uint32_t));
90+
nrf_nvmc_page_erase(_flash_page_addr);
91+
nrf_nvmc_write_words(_flash_page_addr, (uint32_t *)_flash_cache, FL_PAGE_SZ / sizeof(uint32_t));
9692
}
9793

98-
_fl_pg_addr = NO_CACHE;
94+
_flash_page_addr = NO_CACHE;
9995
}
10096

10197
mp_uint_t internal_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) {
@@ -106,39 +102,39 @@ mp_uint_t internal_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num
106102

107103
mp_uint_t internal_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32_t num_blocks) {
108104

109-
#ifdef MICROPY_HW_LED_MSC
105+
#ifdef MICROPY_HW_LED_MSC
110106
port_pin_set_output_level(MICROPY_HW_LED_MSC, true);
111-
#endif
107+
#endif
112108

113109
while (num_blocks) {
114110
uint32_t const addr = lba2addr(lba);
115111
uint32_t const page_addr = addr & ~(FL_PAGE_SZ - 1);
116112

117-
uint32_t count = 8 - (lba%8); // up to page boundary
113+
uint32_t count = 8 - (lba % 8); // up to page boundary
118114
count = MIN(num_blocks, count);
119115

120-
if (page_addr != _fl_pg_addr) {
116+
if (page_addr != _flash_page_addr) {
121117
internal_flash_flush();
122118

123119
// writing previous cached data, skip current data until flashing is done
124120
// tinyusb stack will invoke write_block() with the same parameters later on
125121
// if ( _is_flashing ) return;
126122

127-
_fl_pg_addr = page_addr;
128-
memcpy(_fl_cache, (void *)page_addr, FL_PAGE_SZ);
123+
_flash_page_addr = page_addr;
124+
memcpy(_flash_cache, (void *)page_addr, FL_PAGE_SZ);
129125
}
130126

131-
memcpy(_fl_cache + (addr & (FL_PAGE_SZ - 1)), src, count*FILESYSTEM_BLOCK_SIZE);
127+
memcpy(_flash_cache + (addr & (FL_PAGE_SZ - 1)), src, count * FILESYSTEM_BLOCK_SIZE);
132128

133129
// adjust for next run
134130
lba += count;
135-
src += count*FILESYSTEM_BLOCK_SIZE;
131+
src += count * FILESYSTEM_BLOCK_SIZE;
136132
num_blocks -= count;
137133
}
138134

139-
#ifdef MICROPY_HW_LED_MSC
135+
#ifdef MICROPY_HW_LED_MSC
140136
port_pin_set_output_level(MICROPY_HW_LED_MSC, false);
141-
#endif
137+
#endif
142138

143139
return 0; // success
144140
}
@@ -203,6 +199,10 @@ const mp_obj_type_t internal_flash_type = {
203199
.locals_dict = (mp_obj_t)&internal_flash_obj_locals_dict,
204200
};
205201

202+
/*------------------------------------------------------------------*/
203+
/* Flash API
204+
*------------------------------------------------------------------*/
205+
206206
void flash_init_vfs(fs_user_mount_t *vfs) {
207207
vfs->base.type = &mp_fat_vfs_type;
208208
vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL;

0 commit comments

Comments
 (0)