Skip to content

Commit 5e0195d

Browse files
committed
update tinyusb, correct neopixel for usb enumeration
added binary for feather nrf52840
1 parent 12d68f5 commit 5e0195d

File tree

9 files changed

+1754
-1738
lines changed

9 files changed

+1754
-1738
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ C_SOURCE_FILES += $(TUSB_PATH)/portable/nordic/nrf5x/dcd_nrf5x.c
170170
C_SOURCE_FILES += $(TUSB_PATH)/portable/nordic/nrf5x/hal_nrf5x.c
171171
C_SOURCE_FILES += $(TUSB_PATH)/common/tusb_fifo.c
172172
C_SOURCE_FILES += $(TUSB_PATH)/device/usbd.c
173+
C_SOURCE_FILES += $(TUSB_PATH)/device/usbd_control.c
173174
C_SOURCE_FILES += $(TUSB_PATH)/class/cdc/cdc_device.c
174175
C_SOURCE_FILES += $(TUSB_PATH)/class/msc/msc_device.c
175176
C_SOURCE_FILES += $(TUSB_PATH)/class/custom/custom_device.c

bin/feather_nrf52840_express/6.1.1r0/feather_nrf52840_express_bootloader_s140_6.1.1r0.hex

Lines changed: 1721 additions & 1709 deletions
Large diffs are not rendered by default.
192 Bytes
Binary file not shown.

lib/tinyusb

Submodule tinyusb updated 204 files

src/boards.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void board_init(void)
8787
extern void neopixel_init(void);
8888
neopixel_init();
8989

90-
uint8_t grb[] = { 0, 255, 0 };
90+
uint8_t grb[3] = { 0, 255, 0 };
9191
neopixel_write(grb);
9292
#endif
9393

@@ -148,25 +148,28 @@ void pwm_teardown(NRF_PWM_Type* pwm )
148148

149149
void led_pwm_init(uint32_t led_pin)
150150
{
151-
pwm_teardown ((led_pin == LED_RED) ? NRF_PWM0 : NRF_PWM1);
152-
}
151+
NRF_PWM_Type* pwm = (led_pin == LED_RED) ? NRF_PWM0 : NRF_PWM1;
153152

154-
void led_pwm_teardown(uint32_t led_pin)
155-
{
156-
NRF_PWM_Type* pwm = (led_pin == LED_RED) ? NRF_PWM0 : NRF_PWM1;
153+
pwm->MODE = PWM_MODE_UPDOWN_UpAndDown;
154+
pwm->COUNTERTOP = PWM_MAXCOUNT;
155+
pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_128;
156+
pwm->DECODER = PWM_DECODER_LOAD_Individual;
157+
pwm->LOOP = 0;
157158

158-
pwm->TASKS_SEQSTART[0] = 0;
159-
pwm->ENABLE = 0;
159+
pwm->SEQ[0].PTR = (uint32_t) (led_pin == LED_RED ? _pwm_red_seq : _pwm_blue_seq);
160+
pwm->SEQ[0].CNT = PWM_CHANNEL_NUM; // default mode is Individual --> count must be 4
161+
pwm->SEQ[0].REFRESH = 0;
162+
pwm->SEQ[0].ENDDELAY = 0;
160163

161-
pwm->PSEL.OUT[0] = 0xFFFFFFFF;
164+
pwm->PSEL.OUT[0] = led_pin;
162165

163-
pwm->MODE = 0;
164-
pwm->COUNTERTOP = 0x3FF;
165-
pwm->PRESCALER = 0;
166-
pwm->DECODER = 0;
167-
pwm->LOOP = 0;
168-
pwm->SEQ[0].PTR = 0;
169-
pwm->SEQ[0].CNT = 0;
166+
pwm->ENABLE = 1;
167+
pwm->TASKS_SEQSTART[0] = 1;
168+
}
169+
170+
void led_pwm_teardown(uint32_t led_pin)
171+
{
172+
pwm_teardown ((led_pin == LED_RED) ? NRF_PWM0 : NRF_PWM1);
170173
}
171174

172175
void led_pwm_disable(uint32_t led_pin)
@@ -278,7 +281,6 @@ void neopixel_write (uint8_t *pixels)
278281

279282
NRF_PWM_Type* pwm = NRF_PWM2;
280283

281-
282284
nrf_pwm_seq_ptr_set(pwm, 0, pixels_pattern);
283285
nrf_pwm_seq_cnt_set(pwm, 0, sizeof(pixels_pattern)/2);
284286
nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);

src/segger/Adafruit_nRF52_Bootloader.emProject

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
<file file_name="../../lib/tinyusb/src/device/usbd.c" />
214214
<file file_name="../../lib/tinyusb/src/device/usbd.h" />
215215
<file file_name="../../lib/tinyusb/src/device/usbd_pvt.h" />
216+
<file file_name="../../lib/tinyusb/src/device/usbd_control.c" />
216217
</folder>
217218
<folder Name="osal">
218219
<file file_name="../../lib/tinyusb/src/osal/osal.c" />

src/usb/msc_uf2.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buf
130130

131131
// Callback invoked when received WRITE10 command.
132132
// Process data in buffer to disk's storage and return number of written bytes
133-
int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
133+
int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize)
134134
{
135135
(void) lun;
136136

@@ -148,4 +148,12 @@ int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* bu
148148
return (wr_ret < 0) ? bufsize : count;
149149
}
150150

151+
void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size)
152+
{
153+
(void) lun;
154+
155+
*block_count = UF2_NUM_BLOCKS;
156+
*block_size = 512;
157+
}
158+
151159
#endif

src/usb/tusb_config.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
extern "C" {
4444
#endif
4545

46-
#include "uf2/uf2cfg.h" // for block num
47-
4846
//--------------------------------------------------------------------+
4947
// COMMON CONFIGURATION
5048
//--------------------------------------------------------------------+
@@ -98,12 +96,6 @@
9896
// Number of supported Logical Unit Number
9997
#define CFG_TUD_MSC_MAXLUN 1
10098

101-
// Number of Blocks
102-
#define CFG_TUD_MSC_BLOCK_NUM UF2_NUM_BLOCKS
103-
104-
// Block size
105-
#define CFG_TUD_MSC_BLOCK_SZ 512
106-
10799
// Buffer size for each read/write transfer, the more the better
108100
#define CFG_TUD_MSC_BUFSIZE (4*1024)
109101

src/usb/usb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ void usb_teardown(void)
158158
void tud_mount_cb(void)
159159
{
160160
#ifdef LED_NEOPIXEL
161-
uint8_t grb[] = { 255, 0, 0 };
161+
uint8_t grb[3] = { 255, 0, 0 };
162162
neopixel_write(grb);
163163
#endif
164164
}
165165

166166
void tud_umount_cb(void)
167167
{
168168
#ifdef LED_NEOPIXEL
169-
uint8_t grb[] = { 0, 255, 0 };
169+
uint8_t grb[3] = { 0, 255, 0 };
170170
neopixel_write(grb);
171171
#endif
172172
}

0 commit comments

Comments
 (0)