mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-19 06:40:45 +00:00
add board_buttons API and refractor device keyboard app
This commit is contained in:
parent
f39444a065
commit
4b8c0d97c6
@ -124,6 +124,8 @@ void board_leds(uint32_t on_mask, uint32_t off_mask);
|
||||
uint8_t board_uart_getchar(void);
|
||||
void board_uart_putchar(uint8_t c);
|
||||
|
||||
uint32_t board_buttons(void);
|
||||
|
||||
extern volatile uint32_t system_ticks;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -68,7 +68,6 @@ void board_init(void)
|
||||
//P0_21 instead of P2_9 as USB connect
|
||||
#endif
|
||||
|
||||
#if CFG_UART_ENABLE
|
||||
//------------- UART init -------------//
|
||||
|
||||
PINSEL_CFG_Type PinCfg =
|
||||
@ -91,7 +90,6 @@ void board_init(void)
|
||||
|
||||
UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
|
||||
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -111,8 +109,6 @@ void board_leds(uint32_t on_mask, uint32_t off_mask)
|
||||
//--------------------------------------------------------------------+
|
||||
// UART
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_UART_ENABLE
|
||||
|
||||
void board_uart_putchar(uint8_t c)
|
||||
{
|
||||
UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
|
||||
@ -124,5 +120,3 @@ uint8_t board_uart_getchar(void)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -40,18 +40,39 @@
|
||||
|
||||
#if BOARD == BOARD_RF1GHZNODE
|
||||
|
||||
#define LED_PORT (1)
|
||||
#define LED_PIN (31)
|
||||
#define LED_ON (0)
|
||||
#define LED_OFF (1)
|
||||
|
||||
enum {
|
||||
BOARD_BUTTON_COUNT = 1
|
||||
};
|
||||
|
||||
const static struct {
|
||||
uint8_t port;
|
||||
uint8_t pin;
|
||||
} buttons[BOARD_BUTTON_COUNT] = { 0, 1 };
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
SystemInit();
|
||||
|
||||
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
|
||||
SysTick_Config(SystemCoreClock / CFG_TICKS_PER_SECOND); // 1 msec tick timer
|
||||
#endif
|
||||
|
||||
GPIOInit();
|
||||
|
||||
GPIOSetDir(CFG_LED_PORT, CFG_LED_PIN, 1);
|
||||
//------------- LED -------------//
|
||||
GPIOSetDir(LED_PORT, LED_PIN, 1);
|
||||
board_leds(0x01, 0); // turn off the led first
|
||||
|
||||
#if CFG_UART_ENABLE
|
||||
//------------- BUTTON -------------//
|
||||
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOSetDir(buttons[i].port, buttons[i].pin, 0);
|
||||
|
||||
//------------- UART -------------//
|
||||
UARTInit(CFG_UART_BAUDRATE);
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -61,28 +82,34 @@ void board_leds(uint32_t on_mask, uint32_t off_mask)
|
||||
{
|
||||
if (on_mask & BIT_(0))
|
||||
{
|
||||
GPIOSetBitValue(CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);
|
||||
GPIOSetBitValue(LED_PORT, LED_PIN, LED_ON);
|
||||
}else if (off_mask & BIT_(0))
|
||||
{
|
||||
GPIOSetBitValue(CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);
|
||||
GPIOSetBitValue(LED_PORT, LED_PIN, LED_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Buttons
|
||||
//--------------------------------------------------------------------+
|
||||
uint32_t board_buttons(void)
|
||||
{
|
||||
// for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIOGetPinValue(buttons[i].port, buttons[i].pin);
|
||||
return GPIOGetPinValue(buttons[0].port, buttons[0].pin) ? 0 : 1; // button is active low
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// UART
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_UART_ENABLE
|
||||
uint32_t board_uart_send(uint8_t *buffer, uint32_t length)
|
||||
void board_uart_putchar(uint8_t c)
|
||||
{
|
||||
UARTSend(buffer, length);
|
||||
return length;
|
||||
UARTSend(&c, 1);
|
||||
}
|
||||
|
||||
uint32_t board_uart_recv(uint8_t *buffer, uint32_t length)
|
||||
uint8_t board_uart_getchar(void)
|
||||
{
|
||||
// *buffer = get_key(); TODO cannot find available code for uart getchar
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -36,12 +36,6 @@
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
/** \file
|
||||
* \brief TBD
|
||||
*
|
||||
* \note TBD
|
||||
*/
|
||||
|
||||
/** \ingroup TBD
|
||||
* \defgroup TBD
|
||||
* \brief TBD
|
||||
@ -60,12 +54,8 @@
|
||||
#include "lpc11uxx/LPC11Uxx_DriverLib/lpc11uxx_gpio.h"
|
||||
#include "lpc11uxx/LPC11Uxx_DriverLib/lpc11uxx_uart.h"
|
||||
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
|
||||
|
||||
#define CFG_LED_PORT (1)
|
||||
#define CFG_LED_PIN (31)
|
||||
#define CFG_LED_ON (0)
|
||||
#define CFG_LED_OFF (1)
|
||||
//#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -121,7 +121,7 @@
|
||||
<builder buildPath="${workspace_loc:/device_keyboard/Debug}" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="com.crt.advproject.builder.exe.debug.1603637140" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="com.crt.advproject.builder.exe.debug"/>
|
||||
<tool id="com.crt.advproject.cpp.exe.debug.1912680765" name="MCU C++ Compiler" superClass="com.crt.advproject.cpp.exe.debug"/>
|
||||
<tool command="arm-none-eabi-gcc" commandLinePattern="${COMMAND} ${FLAGS} ${CFLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="com.crt.advproject.gcc.exe.debug.901878888" name="MCU C Compiler" superClass="com.crt.advproject.gcc.exe.debug">
|
||||
<option id="com.crt.advproject.gcc.arch.227583493" name="Architecture" superClass="com.crt.advproject.gcc.arch" value="com.crt.advproject.gcc.target.cm3" valueType="enumerated"/>
|
||||
<option id="com.crt.advproject.gcc.arch.227583493" name="Architecture" superClass="com.crt.advproject.gcc.arch" value="com.crt.advproject.gcc.target.cm0" valueType="enumerated"/>
|
||||
<option id="com.crt.advproject.gcc.thumb.1429919562" name="Thumb mode" superClass="com.crt.advproject.gcc.thumb" value="true" valueType="boolean"/>
|
||||
<option id="gnu.c.compiler.option.preprocessor.def.symbols.690334585" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="__REDLIB__"/>
|
||||
@ -134,10 +134,10 @@
|
||||
</option>
|
||||
<option id="gnu.c.compiler.option.misc.other.1222444467" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections" valueType="string"/>
|
||||
<option id="gnu.c.compiler.option.include.paths.2143003127" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/bsp/lpc11uxx/CMSISv2p00_LPC11Uxx/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/bsp}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/tinyusb}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}}""/>
|
||||
</option>
|
||||
<option id="gnu.c.compiler.option.include.files.1663093508" name="Include files (-include)" superClass="gnu.c.compiler.option.include.files"/>
|
||||
<option id="com.crt.advproject.c.misc.dialect.378026709" name="C Dialect" superClass="com.crt.advproject.c.misc.dialect" value="com.crt.advproject.misc.dialect.gnu99" valueType="enumerated"/>
|
||||
@ -146,7 +146,7 @@
|
||||
<inputType id="com.crt.advproject.compiler.input.1660235734" superClass="com.crt.advproject.compiler.input"/>
|
||||
</tool>
|
||||
<tool command="arm-none-eabi-gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GASErrorParser" id="com.crt.advproject.gas.exe.debug.1919954827" name="MCU Assembler" superClass="com.crt.advproject.gas.exe.debug">
|
||||
<option id="com.crt.advproject.gas.arch.62277376" name="Architecture" superClass="com.crt.advproject.gas.arch" value="com.crt.advproject.gas.target.cm3" valueType="enumerated"/>
|
||||
<option id="com.crt.advproject.gas.arch.62277376" name="Architecture" superClass="com.crt.advproject.gas.arch" value="com.crt.advproject.gas.target.cm0" valueType="enumerated"/>
|
||||
<option id="com.crt.advproject.gas.thumb.567012827" name="Thumb mode" superClass="com.crt.advproject.gas.thumb" value="true" valueType="boolean"/>
|
||||
<option id="gnu.both.asm.option.flags.crt.1544048579" name="Assembler flags" superClass="gnu.both.asm.option.flags.crt" value="-c -x assembler-with-cpp -D__REDLIB__ -DDEBUG -D__CODE_RED" valueType="string"/>
|
||||
<inputType id="com.crt.advproject.assembler.input.2112542401" name="Additional Assembly Source Files" superClass="com.crt.advproject.assembler.input"/>
|
||||
@ -154,7 +154,7 @@
|
||||
</tool>
|
||||
<tool id="com.crt.advproject.link.cpp.exe.debug.438186138" name="MCU C++ Linker" superClass="com.crt.advproject.link.cpp.exe.debug"/>
|
||||
<tool command="arm-none-eabi-gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GLDErrorParser" id="com.crt.advproject.link.exe.debug.332994381" name="MCU Linker" superClass="com.crt.advproject.link.exe.debug">
|
||||
<option id="com.crt.advproject.link.arch.5439507" name="Architecture" superClass="com.crt.advproject.link.arch" value="com.crt.advproject.link.target.cm3" valueType="enumerated"/>
|
||||
<option id="com.crt.advproject.link.arch.5439507" name="Architecture" superClass="com.crt.advproject.link.arch" value="com.crt.advproject.link.target.cm0" valueType="enumerated"/>
|
||||
<option id="com.crt.advproject.link.thumb.1052282054" name="Thumb mode" superClass="com.crt.advproject.link.thumb" value="true" valueType="boolean"/>
|
||||
<option id="com.crt.advproject.link.script.1723865493" name="Linker script" superClass="com.crt.advproject.link.script" value=""device_os_none_Board_rf1ghznode.ld"" valueType="string"/>
|
||||
<option id="com.crt.advproject.link.manage.314167409" name="Manage linker script" superClass="com.crt.advproject.link.manage" value="true" valueType="boolean"/>
|
||||
|
1805
demos/device/device_os_none/device_os_none.uvopt
Normal file
1805
demos/device/device_os_none/device_os_none.uvopt
Normal file
File diff suppressed because it is too large
Load Diff
@ -127,29 +127,28 @@ OSAL_TASK_FUNCTION( keyboardd_app_task ) (void* p_task_para)
|
||||
{
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
if (tusbd_is_configured(0) && (keyboardd_report_count++ < 5) )
|
||||
osal_task_delay(100);
|
||||
|
||||
if ( tusbd_is_configured(0) )
|
||||
{
|
||||
if (!tusbd_hid_keyboard_is_busy(0))
|
||||
static uint32_t button_mask = 0;
|
||||
|
||||
uint32_t new_button_mask = board_buttons();
|
||||
|
||||
//------------- Key pressed -------------//
|
||||
if ( (button_mask != new_button_mask) && !tusbd_hid_keyboard_is_busy(0) )
|
||||
{
|
||||
//------------- Key pressed -------------//
|
||||
keyboard_report.keycode[0] = 0x04;
|
||||
button_mask = new_button_mask;
|
||||
|
||||
for (uint8_t i=0; i<6; i++)
|
||||
{ // demo support up to 6 buttons, button0 = 'a', button1 = 'b', etc ...
|
||||
keyboard_report.keycode[i] = BIT_TEST_(button_mask, i) ? (0x04+i) : 0;
|
||||
}
|
||||
|
||||
tusbd_hid_keyboard_send(0, &keyboard_report );
|
||||
|
||||
while( tusbd_hid_keyboard_is_busy(0) )
|
||||
{ // delay for transfer complete
|
||||
osal_task_delay(10);
|
||||
}
|
||||
|
||||
//------------- Key released -------------//
|
||||
if (!tusbd_hid_keyboard_is_busy(0))
|
||||
{
|
||||
keyboard_report.keycode[0] = 0x00;
|
||||
tusbd_hid_keyboard_send(0, &keyboard_report );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osal_task_delay(1000);
|
||||
|
||||
OSAL_TASK_LOOP_END
|
||||
}
|
||||
|
@ -82,11 +82,11 @@
|
||||
#define TUSB_CFG_DEVICE_FULLSPEED 1 // TODO refractor, remove
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD 0
|
||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD 1
|
||||
#define TUSB_CFG_DEVICE_HID_MOUSE 0
|
||||
#define TUSB_CFG_DEVICE_HID_GENERIC 0
|
||||
#define TUSB_CFG_DEVICE_MSC 0
|
||||
#define TUSB_CFG_DEVICE_CDC 1
|
||||
#define TUSB_CFG_DEVICE_CDC 0
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// COMMON CONFIGURATION
|
||||
@ -99,12 +99,10 @@
|
||||
#define TUSB_CFG_OS_TICKS_PER_SECOND 1000
|
||||
|
||||
#ifdef __CODE_RED // compiled with lpcxpresso
|
||||
#if (TUSB_CFG_MCU == MCU_LPC11UXX) || (TUSB_CFG_MCU == MCU_LPC13UXX)
|
||||
#if (TUSB_CFG_MCU == MCU_LPC11UXX) || (TUSB_CFG_MCU == MCU_LPC13UXX) || (TUSB_CFG_MCU == MCU_LPC175X_6X)
|
||||
#define TUSB_RAM_SECTION ".data.$RAM2"
|
||||
#elif (TUSB_CFG_MCU == MCU_LPC43XX)
|
||||
#define TUSB_RAM_SECTION ".data.$RAM3"
|
||||
#elif (TUSB_CFG_MCU == MCU_LPC175X_6X)
|
||||
#define TUSB_RAM_SECTION ".data.$RAM2"
|
||||
#else
|
||||
#error Please define USB RAM section
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user