diff options
| author | hathach <[email protected]> | 2018-03-11 14:37:01 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-03-11 14:37:01 +0700 |
| commit | fd250b92cb62780dee5d99b49bbcbc05080b6987 (patch) | |
| tree | c2c1b22e5aab234d3a865802d3bb0a8734d28987 /examples/obsolete/device/src | |
| parent | 3582d2301d52c88289eb76d9d98a017035d2c5d7 (diff) | |
clean up example
Diffstat (limited to 'examples/obsolete/device/src')
| -rw-r--r-- | examples/obsolete/device/src/cdc_device_app.c | 77 | ||||
| -rw-r--r-- | examples/obsolete/device/src/cdc_device_app.h | 4 | ||||
| -rw-r--r-- | examples/obsolete/device/src/keyboard_device_app.c | 12 | ||||
| -rw-r--r-- | examples/obsolete/device/src/keyboard_device_app.h | 4 | ||||
| -rw-r--r-- | examples/obsolete/device/src/main.c | 68 | ||||
| -rw-r--r-- | examples/obsolete/device/src/mouse_device_app.c | 10 | ||||
| -rw-r--r-- | examples/obsolete/device/src/mouse_device_app.h | 4 | ||||
| -rw-r--r-- | examples/obsolete/device/src/msc_device_app.c | 6 | ||||
| -rw-r--r-- | examples/obsolete/device/src/msc_device_app.h | 4 | ||||
| -rw-r--r-- | examples/obsolete/device/src/msc_device_ramdisk.c | 4 | ||||
| -rw-r--r-- | examples/obsolete/device/src/msc_device_romdisk.c | 4 |
11 files changed, 95 insertions, 102 deletions
diff --git a/examples/obsolete/device/src/cdc_device_app.c b/examples/obsolete/device/src/cdc_device_app.c index 6ef6e753f..d65b695f8 100644 --- a/examples/obsolete/device/src/cdc_device_app.c +++ b/examples/obsolete/device/src/cdc_device_app.c @@ -56,63 +56,22 @@ static osal_semaphore_t sem_hdl; //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -TUSB_CFG_ATTR_USBRAM static uint8_t serial_rx_buffer[SERIAL_BUFFER_SIZE]; -TUSB_CFG_ATTR_USBRAM static uint8_t serial_tx_buffer[SERIAL_BUFFER_SIZE]; - -FIFO_DEF(fifo_serial, SERIAL_BUFFER_SIZE, uint8_t, true); //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void cdc_serial_app_mount(uint8_t coreid) +void cdc_serial_app_mount(uint8_t port) { - osal_semaphore_reset(sem_hdl); - - tud_cdc_receive(coreid, serial_rx_buffer, SERIAL_BUFFER_SIZE, true); } -void cdc_serial_app_umount(uint8_t coreid) +void cdc_serial_app_umount(uint8_t port) { } -void tud_cdc_rx_cb(uint8_t coreid, uint32_t xferred_bytes) +void tud_cdc_rx_cb(uint8_t port) { - fifo_write_n(&fifo_serial, serial_rx_buffer, xferred_bytes); - osal_semaphore_post(sem_hdl); // notify main task -} - - -void tud_cdc_xfer_cb(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) -{ - switch ( pipe_id ) - { - case CDC_PIPE_DATA_OUT: - switch(event) - { - case TUSB_EVENT_XFER_COMPLETE: - for(uint8_t i=0; i<xferred_bytes; i++) - { - fifo_write(&fifo_serial, serial_rx_buffer+i); - } - osal_semaphore_post(sem_hdl); // notify main task - break; - case TUSB_EVENT_XFER_ERROR: - tud_cdc_receive(0, serial_rx_buffer, SERIAL_BUFFER_SIZE, true); // ignore, queue transfer again - break; - - case TUSB_EVENT_XFER_STALLED: - default : - break; - } - break; - - case CDC_PIPE_DATA_IN: - case CDC_PIPE_NOTIFICATION: - default: - break; - } } //--------------------------------------------------------------------+ @@ -120,10 +79,6 @@ void tud_cdc_xfer_cb(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id, u //--------------------------------------------------------------------+ void cdc_serial_app_init(void) { - sem_hdl = osal_semaphore_create(1, 0); - VERIFY(sem_hdl, ); - - osal_task_create(cdc_serial_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO); } tusb_error_t cdc_serial_subtask(void); @@ -141,30 +96,14 @@ tusb_error_t cdc_serial_subtask(void) { OSAL_SUBTASK_BEGIN - tusb_error_t error; - - osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); - (void) error; // suppress compiler's warnings - - if ( tud_mounted(0) ) + if ( tud_mounted(0) && tud_cdc_available(0) ) { - // echo back data in the fifo - if ( !tud_cdc_busy(0, CDC_PIPE_DATA_IN) ) - { - uint16_t count=0; - while( fifo_read(&fifo_serial, &serial_tx_buffer[count]) ) - { - count++; - } + uint8_t buf[64]; - if (count) - { - tud_cdc_send(0, serial_tx_buffer, count, false); - } - } + // read and echo back + uint32_t count = tud_cdc_read(0, buf, sizeof(buf)); - // getting more data from host - tud_cdc_receive(0, serial_rx_buffer, SERIAL_BUFFER_SIZE, true); + tud_cdc_write(0, buf, count); } OSAL_SUBTASK_END diff --git a/examples/obsolete/device/src/cdc_device_app.h b/examples/obsolete/device/src/cdc_device_app.h index 5433da207..41c619864 100644 --- a/examples/obsolete/device/src/cdc_device_app.h +++ b/examples/obsolete/device/src/cdc_device_app.h @@ -58,8 +58,8 @@ void cdc_serial_app_init(void); void cdc_serial_app_task(void* param); -void cdc_serial_app_mount(uint8_t coreid); -void cdc_serial_app_umount(uint8_t coreid); +void cdc_serial_app_mount(uint8_t port); +void cdc_serial_app_umount(uint8_t port); #else diff --git a/examples/obsolete/device/src/keyboard_device_app.c b/examples/obsolete/device/src/keyboard_device_app.c index b4a9cb69a..edd3cb388 100644 --- a/examples/obsolete/device/src/keyboard_device_app.c +++ b/examples/obsolete/device/src/keyboard_device_app.c @@ -56,17 +56,17 @@ TUSB_CFG_ATTR_USBRAM hid_keyboard_report_t keyboard_report; //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void keyboard_app_mount(uint8_t coreid) +void keyboard_app_mount(uint8_t port) { } -void keyboard_app_umount(uint8_t coreid) +void keyboard_app_umount(uint8_t port) { } -void tud_hid_keyboard_cb(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes) +void tud_hid_keyboard_cb(uint8_t port, tusb_event_t event, uint32_t xferred_bytes) { switch(event) { @@ -77,7 +77,7 @@ void tud_hid_keyboard_cb(uint8_t coreid, tusb_event_t event, uint32_t xferred_by } } -uint16_t tud_hid_keyboard_get_report_cb(uint8_t coreid, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length) +uint16_t tud_hid_keyboard_get_report_cb(uint8_t port, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length) { // get other than input report is not supported by this keyboard demo if ( report_type != HID_REQUEST_REPORT_INPUT ) return 0; @@ -86,7 +86,7 @@ uint16_t tud_hid_keyboard_get_report_cb(uint8_t coreid, hid_request_report_type_ return requested_length; } -void tud_hid_keyboard_set_report_cb(uint8_t coreid, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length) +void tud_hid_keyboard_set_report_cb(uint8_t port, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length) { // set other than output report is not supported by this keyboard demo if ( report_type != HID_REQUEST_REPORT_OUTPUT ) return; @@ -98,6 +98,8 @@ void tud_hid_keyboard_set_report_cb(uint8_t coreid, hid_request_report_type_t re if (kbd_led & KEYBOARD_LED_CAPSLOCK ) interval_divider *= 2; if (kbd_led & KEYBOARD_LED_SCROLLLOCK) interval_divider *= 2; + // TODO remove + extern void led_blinking_set_interval(uint32_t ms); led_blinking_set_interval( 1000 / interval_divider); } diff --git a/examples/obsolete/device/src/keyboard_device_app.h b/examples/obsolete/device/src/keyboard_device_app.h index 2c0817280..576851a7a 100644 --- a/examples/obsolete/device/src/keyboard_device_app.h +++ b/examples/obsolete/device/src/keyboard_device_app.h @@ -58,8 +58,8 @@ void keyboard_app_init(void); void keyboard_app_task(void* param); -void keyboard_app_mount(uint8_t coreid); -void keyboard_app_umount(uint8_t coreid); +void keyboard_app_mount(uint8_t port); +void keyboard_app_umount(uint8_t port); #else diff --git a/examples/obsolete/device/src/main.c b/examples/obsolete/device/src/main.c index 42456ae62..cb02cbc1d 100644 --- a/examples/obsolete/device/src/main.c +++ b/examples/obsolete/device/src/main.c @@ -44,6 +44,7 @@ #include <string.h> #include "bsp/board.h" +#include "app_os_prio.h" #include "tusb.h" #include "msc_device_app.h" @@ -59,6 +60,9 @@ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ void print_greeting(void); +void led_blinking_init(void); +void led_blinking_task(void* param); + #if TUSB_CFG_OS == TUSB_OS_NONE // like a real RTOS, this function is a main loop invoking each task in application and never return @@ -107,18 +111,66 @@ int main(void) //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void tud_mount_cb(uint8_t coreid) +void tud_mount_cb(uint8_t port) +{ + cdc_serial_app_mount(port); + keyboard_app_mount(port); + msc_app_mount(port); +} + +void tud_umount_cb(uint8_t port) +{ + cdc_serial_app_umount(port); + keyboard_app_umount(port); + msc_app_umount(port); +} + +//--------------------------------------------------------------------+ +// BLINKING TASK +//--------------------------------------------------------------------+ +static uint32_t led_blink_interval_ms = 1000; // default is 1 second + +void led_blinking_init(void) +{ + led_blink_interval_ms = 1000; + osal_task_create(led_blinking_task, "blinky", 128, NULL, LED_BLINKING_APP_TASK_PRIO); +} + +void led_blinking_set_interval(uint32_t ms) +{ + led_blink_interval_ms = ms; +} + +tusb_error_t led_blinking_subtask(void); +void led_blinking_task(void* param) { - cdc_serial_app_mount(coreid); - keyboard_app_mount(coreid); - msc_app_mount(coreid); + (void) param; + + OSAL_TASK_BEGIN + led_blinking_subtask(); + OSAL_TASK_END } -void tud_umount_cb(uint8_t coreid) +tusb_error_t led_blinking_subtask(void) { - cdc_serial_app_umount(coreid); - keyboard_app_umount(coreid); - msc_app_umount(coreid); + OSAL_SUBTASK_BEGIN + + static uint32_t led_on_mask = 0; + + osal_task_delay(led_blink_interval_ms); + + board_leds(led_on_mask, 1 - led_on_mask); + led_on_mask = 1 - led_on_mask; // toggle + +// uint32_t btn_mask; +// btn_mask = board_buttons(); +// +// for(uint8_t i=0; i<32; i++) +// { +// if ( BIT_TEST_(btn_mask, i) ) printf("button %d is pressed\n", i); +// } + + OSAL_SUBTASK_END } //--------------------------------------------------------------------+ diff --git a/examples/obsolete/device/src/mouse_device_app.c b/examples/obsolete/device/src/mouse_device_app.c index 055a7b699..512b095fa 100644 --- a/examples/obsolete/device/src/mouse_device_app.c +++ b/examples/obsolete/device/src/mouse_device_app.c @@ -56,17 +56,17 @@ TUSB_CFG_ATTR_USBRAM hid_mouse_report_t mouse_report; //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void mouse_app_mount(uint8_t coreid) +void mouse_app_mount(uint8_t port) { } -void mouse_app_umount(uint8_t coreid) +void mouse_app_umount(uint8_t port) { } -void tusbd_hid_mouse_cb(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes) +void tusbd_hid_mouse_cb(uint8_t port, tusb_event_t event, uint32_t xferred_bytes) { switch(event) { @@ -77,7 +77,7 @@ void tusbd_hid_mouse_cb(uint8_t coreid, tusb_event_t event, uint32_t xferred_byt } } -uint16_t tusbd_hid_mouse_get_report_cb(uint8_t coreid, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length) +uint16_t tusbd_hid_mouse_get_report_cb(uint8_t port, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length) { if ( report_type != HID_REQUEST_REPORT_INPUT ) return 0; // not support other report type for this mouse demo @@ -85,7 +85,7 @@ uint16_t tusbd_hid_mouse_get_report_cb(uint8_t coreid, hid_request_report_type_t return requested_length; } -void tusbd_hid_mouse_set_report_cb(uint8_t coreid, hid_request_report_type_t report_type, uint8_t report_data[], uint16_t length) +void tusbd_hid_mouse_set_report_cb(uint8_t port, hid_request_report_type_t report_type, uint8_t report_data[], uint16_t length) { // mouse demo does not support set report --> do nothing } diff --git a/examples/obsolete/device/src/mouse_device_app.h b/examples/obsolete/device/src/mouse_device_app.h index 027f3afe2..daf2bcb7f 100644 --- a/examples/obsolete/device/src/mouse_device_app.h +++ b/examples/obsolete/device/src/mouse_device_app.h @@ -57,8 +57,8 @@ void mouse_app_init(void); void mouse_app_task(void * param); -void mouse_app_mount(uint8_t coreid); -void mouse_app_umount(uint8_t coreid); +void mouse_app_mount(uint8_t port); +void mouse_app_umount(uint8_t port); #else diff --git a/examples/obsolete/device/src/msc_device_app.c b/examples/obsolete/device/src/msc_device_app.c index 240f8f4dc..906c1fa09 100644 --- a/examples/obsolete/device/src/msc_device_app.c +++ b/examples/obsolete/device/src/msc_device_app.c @@ -89,17 +89,17 @@ static scsi_mode_parameters_t const msc_dev_mode_para = //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void msc_app_mount(uint8_t coreid) +void msc_app_mount(uint8_t port) { } -void msc_app_umount(uint8_t coreid) +void msc_app_umount(uint8_t port) { } -msc_csw_status_t tud_msc_scsi_cb (uint8_t coreid, uint8_t lun, uint8_t scsi_cmd[16], void const ** pp_buffer, uint16_t* p_length) +msc_csw_status_t tud_msc_scsi_cb (uint8_t port, uint8_t lun, uint8_t scsi_cmd[16], void const ** pp_buffer, uint16_t* p_length) { // read10 & write10 has their own callback and MUST not be handled here switch (scsi_cmd[0]) diff --git a/examples/obsolete/device/src/msc_device_app.h b/examples/obsolete/device/src/msc_device_app.h index 47803b7d4..b0ad440ba 100644 --- a/examples/obsolete/device/src/msc_device_app.h +++ b/examples/obsolete/device/src/msc_device_app.h @@ -72,8 +72,8 @@ issue at github.com/hathach/tinyusb" void msc_app_init(void); void msc_app_task(void* param); -void msc_app_mount(uint8_t coreid); -void msc_app_umount(uint8_t coreid); +void msc_app_mount(uint8_t port); +void msc_app_umount(uint8_t port); extern scsi_sense_fixed_data_t mscd_sense_data; diff --git a/examples/obsolete/device/src/msc_device_ramdisk.c b/examples/obsolete/device/src/msc_device_ramdisk.c index 37ea923b3..3f9c89dfb 100644 --- a/examples/obsolete/device/src/msc_device_ramdisk.c +++ b/examples/obsolete/device/src/msc_device_ramdisk.c @@ -91,13 +91,13 @@ uint8_t msc_device_ramdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] = //--------------------------------------------------------------------+ // IMPLEMENTATION //--------------------------------------------------------------------+ -uint16_t tud_msc_read10_cb (uint8_t coreid, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) +uint16_t tud_msc_read10_cb (uint8_t port, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) { (*pp_buffer) = msc_device_ramdisk[lba]; return min16_of(block_count, DISK_BLOCK_NUM); } -uint16_t tud_msc_write10_cb(uint8_t coreid, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) +uint16_t tud_msc_write10_cb(uint8_t port, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) { (*pp_buffer) = msc_device_ramdisk[lba]; diff --git a/examples/obsolete/device/src/msc_device_romdisk.c b/examples/obsolete/device/src/msc_device_romdisk.c index 536d22dc7..931e5d367 100644 --- a/examples/obsolete/device/src/msc_device_romdisk.c +++ b/examples/obsolete/device/src/msc_device_romdisk.c @@ -97,7 +97,7 @@ static uint8_t sector_buffer[DISK_BLOCK_SIZE]; //--------------------------------------------------------------------+ // IMPLEMENTATION //--------------------------------------------------------------------+ -uint16_t tusbd_msc_read10_cb (uint8_t coreid, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) +uint16_t tusbd_msc_read10_cb (uint8_t port, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) { memcpy(sector_buffer, msc_device_app_rommdisk[lba], DISK_BLOCK_SIZE); (*pp_buffer) = sector_buffer; @@ -106,7 +106,7 @@ uint16_t tusbd_msc_read10_cb (uint8_t coreid, uint8_t lun, void** pp_buffer, uin } // Stall write10 by return 0, as this is readonly disk -uint16_t tusbd_msc_write10_cb(uint8_t coreid, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) +uint16_t tusbd_msc_write10_cb(uint8_t port, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) { (*pp_buffer) = NULL; |
