Skip to content

Commit

Permalink
Add hid & cdc
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsk committed Aug 1, 2021
1 parent eda52d7 commit 2fead59
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.vscode/settings.json
.vscode
6 changes: 3 additions & 3 deletions firmware/bl_mcu_sdk/bsp/board/bl702/bl702_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
#include "bl706_iot/clock_config.h"
#include "bl706_iot/pinmux_config.h"
#elif defined(sipeed_keyboard)
#include "bl706_iot/peripheral_config.h"
#include "bl706_iot/clock_config.h"
#include "bl706_iot/pinmux_config.h"
#include "sipeed_keyboard/peripheral_config.h"
#include "sipeed_keyboard/clock_config.h"
#include "sipeed_keyboard/pinmux_config.h"
#elif defined(bl706_lp)
#include "bl706_lp/peripheral_config.h"
#include "bl706_lp/clock_config.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#ifdef __cplusplus
extern "C" {
#endif

#include "stdint.h"
#include "sys/cdefs.h"
#include "usbd_core.h"
/*------------------------------------------------------------------------------
* Definitions based on usbcdc11.pdf (www.usb.org)
*----------------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ list(APPEND ADD_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(TARGET_REQUIRED_SRCS ${CMAKE_CURRENT_LIST_DIR}/ble_peripheral_tp_server.c
${CMAKE_CURRENT_LIST_DIR}/smk_ble.c
${CMAKE_CURRENT_LIST_DIR}/smk_usb.c
${CMAKE_CURRENT_LIST_DIR}/smk_hid.c
${CMAKE_CURRENT_LIST_DIR}/smk_cdc.c
${CMAKE_CURRENT_LIST_DIR}/smk_msc.c
${CMAKE_CURRENT_LIST_DIR}/smk_keyscan.c
${BSP_COMMON_DIR}/usb/usb_dc.c
${BSP_COMMON_DIR}/usb/uart_interface.c
${BSP_COMMON_DIR}/spi_sd/bsp_spi_sd.c)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __SMK_CDC_H
#define __SMK_CDC_H

#define CDC_IN_EP 0x84
#define CDC_OUT_EP 0x03
#define CDC_INT_EP 0x85

void smk_cdc_init();

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __SMK_HID_H
#define __SMK_HID_H


#define HID_DESCRIPTOR_LEN 25
#define HID_KEYBOARD_REPORT_DESC_SIZE 63

#define HID_INT_EP 0x81
#define HID_INT_EP_SIZE 8
#define HID_INT_EP_INTERVAL 10

void smk_hid_usb_init();

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __SMK_KEYSCAN_H
#define __SMK_KEYSCAN_H




#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef __SMK_MSC_H
#define __SMK_MSC_H

#include "hal_usb.h"
#include "usbd_core.h"
#include "usbd_msc.h"

#define MSC_IN_EP 0x86
#define MSC_OUT_EP 0x07

void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint16_t *block_size);
int usbd_msc_sector_read(uint32_t sector, uint8_t *buffer, uint32_t length);
int usbd_msc_sector_write(uint32_t sector, uint8_t *buffer, uint32_t length);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include "hal_usb.h"
#include "usbd_core.h"
#include "usbd_msc.h"
#include "smk_msc.h"
#include "smk_cdc.h"
#include "smk_hid.h"


void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint16_t *block_size);
int usbd_msc_sector_read(uint32_t sector, uint8_t *buffer, uint32_t length);
int usbd_msc_sector_write(uint32_t sector, uint8_t *buffer, uint32_t length);
void usb_init();

#endif //__SMK_USB_H
61 changes: 61 additions & 0 deletions firmware/bl_mcu_sdk/examples/keyboard/sipeed_keyboard_68/smk_cdc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "smk_cdc.h"
#include "usbd_cdc.h"
#include "usbd_core.h"
#include "uart_interface.h"
#include "hal_usb.h"
#include "stdint.h"

extern struct device *usb_fs;
extern struct usbd_interface_cfg usb_cdc;

void usbd_cdc_acm_bulk_out(uint8_t ep)
{
usb_dc_receive_to_ringbuffer(usb_fs, &usb_rx_rb, ep);
}

void usbd_cdc_acm_bulk_in(uint8_t ep)
{
usb_dc_send_from_ringbuffer(usb_fs, &uart1_rx_rb, ep);
}
void usbd_cdc_acm_set_line_coding(uint32_t baudrate, uint8_t databits, uint8_t parity, uint8_t stopbits)
{
uart1_config(baudrate, databits, parity, stopbits);
}

void usbd_cdc_acm_set_dtr(bool dtr)
{
dtr_pin_set(dtr);
}

void usbd_cdc_acm_set_rts(bool rts)
{
rts_pin_set(rts);
}

usbd_class_t cdc_class;

usbd_interface_t cdc_cmd_intf;
usbd_interface_t cdc_data_intf;

usbd_endpoint_t cdc_out_ep = {
.ep_addr = CDC_OUT_EP,
.ep_cb = usbd_cdc_acm_bulk_out
};

usbd_endpoint_t cdc_in_ep = {
.ep_addr = CDC_IN_EP,
.ep_cb = usbd_cdc_acm_bulk_in
};

void smk_cdc_init()
{
uart_ringbuffer_init();
uart1_init();
uart1_dtr_init();
uart1_rts_init();

usbd_cdc_add_acm_interface(&cdc_class, &cdc_cmd_intf);
usbd_cdc_add_acm_interface(&cdc_class, &cdc_data_intf);
usbd_interface_add_endpoint(&cdc_data_intf, &cdc_out_ep);
usbd_interface_add_endpoint(&cdc_data_intf, &cdc_in_ep);
}
66 changes: 66 additions & 0 deletions firmware/bl_mcu_sdk/examples/keyboard/sipeed_keyboard_68/smk_hid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "smk_hid.h"
#include "smk_keyscan.h"
#include "hal_usb.h"
#include "usbd_core.h"
#include "usbd_hid.h"

static const uint8_t hid_keyboard_report_desc[HID_KEYBOARD_REPORT_DESC_SIZE] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x95, 0x05, // REPORT_COUNT (5)
0x75, 0x01, // REPORT_SIZE (1)
0x05, 0x08, // USAGE_PAGE (LEDs)
0x19, 0x01, // USAGE_MINIMUM (Num Lock)
0x29, 0x05, // USAGE_MAXIMUM (Kana)
0x91, 0x02, // OUTPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x03, // REPORT_SIZE (3)
0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xFF, // LOGICAL_MAXIMUM (255)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0 // END_COLLECTION
};

extern struct device *usb_fs;

static usbd_class_t hid_class;
static usbd_interface_t hid_intf;

void usbd_hid_int_callback(uint8_t ep)
{
uint8_t sendbuffer[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //A
usbd_ep_write(HID_INT_EP, sendbuffer, 8, NULL);
//MSG("A\r\n");
}

static usbd_endpoint_t hid_in_ep = {
.ep_cb = usbd_hid_int_callback,
.ep_addr = 0x81
};

extern struct device *usb_dc_init(void);

void smk_hid_usb_init()
{
usbd_hid_add_interface(&hid_class, &hid_intf);
usbd_interface_add_endpoint(&hid_intf, &hid_in_ep);
usbd_hid_report_descriptor_register(0, hid_keyboard_report_desc, HID_KEYBOARD_REPORT_DESC_SIZE);
}
Empty file.
Empty file.
Loading

0 comments on commit 2fead59

Please sign in to comment.