1
0
Fork 0

clang-format changes

This commit is contained in:
skullY 2019-08-30 11:19:03 -07:00 committed by skullydazed
parent 61af76a10d
commit b624f32f94
502 changed files with 32259 additions and 39062 deletions

View file

@ -42,11 +42,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include <avr/interrupt.h>
#include "adb.h"
// GCC doesn't inline functions normally
#define data_lo() (ADB_DDR |= (1<<ADB_DATA_BIT))
#define data_hi() (ADB_DDR &= ~(1<<ADB_DATA_BIT))
#define data_in() (ADB_PIN & (1<<ADB_DATA_BIT))
#define data_lo() (ADB_DDR |= (1 << ADB_DATA_BIT))
#define data_hi() (ADB_DDR &= ~(1 << ADB_DATA_BIT))
#define data_in() (ADB_PIN & (1 << ADB_DATA_BIT))
#ifdef ADB_PSW_BIT
static inline void psw_lo(void);
@ -54,18 +53,16 @@ static inline void psw_hi(void);
static inline bool psw_in(void);
#endif
static inline void attention(void);
static inline void place_bit0(void);
static inline void place_bit1(void);
static inline void send_byte(uint8_t data);
static inline void attention(void);
static inline void place_bit0(void);
static inline void place_bit1(void);
static inline void send_byte(uint8_t data);
static inline uint16_t wait_data_lo(uint16_t us);
static inline uint16_t wait_data_hi(uint16_t us);
static inline uint16_t adb_host_dev_recv(uint8_t device);
void adb_host_init(void)
{
ADB_PORT &= ~(1<<ADB_DATA_BIT);
void adb_host_init(void) {
ADB_PORT &= ~(1 << ADB_DATA_BIT);
data_hi();
#ifdef ADB_PSW_BIT
psw_hi();
@ -73,10 +70,7 @@ void adb_host_init(void)
}
#ifdef ADB_PSW_BIT
bool adb_host_psw(void)
{
return psw_in();
}
bool adb_host_psw(void) { return psw_in(); }
#endif
/*
@ -105,11 +99,11 @@ bool adb_host_psw(void)
// bit0:
// 70us bit cell:
// ____________~~~~~~
// 42-49 21-28
// 42-49 21-28
//
// 130us bit cell:
// ____________~~~~~~
// 78-91 39-52
// 78-91 39-52
//
// bit1:
// 70us bit cell:
@ -122,66 +116,50 @@ bool adb_host_psw(void)
//
// [from Apple IIgs Hardware Reference Second Edition]
enum {
ADDR_KEYB = 0x20,
ADDR_MOUSE = 0x30
};
enum { ADDR_KEYB = 0x20, ADDR_MOUSE = 0x30 };
uint16_t adb_host_kbd_recv(void)
{
return adb_host_dev_recv(ADDR_KEYB);
}
uint16_t adb_host_kbd_recv(void) { return adb_host_dev_recv(ADDR_KEYB); }
#ifdef ADB_MOUSE_ENABLE
void adb_mouse_init(void) {
return;
}
void adb_mouse_init(void) { return; }
uint16_t adb_host_mouse_recv(void)
{
return adb_host_dev_recv(ADDR_MOUSE);
}
uint16_t adb_host_mouse_recv(void) { return adb_host_dev_recv(ADDR_MOUSE); }
#endif
static inline uint16_t adb_host_dev_recv(uint8_t device)
{
static inline uint16_t adb_host_dev_recv(uint8_t device) {
uint16_t data = 0;
cli();
attention();
send_byte(device|0x0C); // Addr:Keyboard(0010)/Mouse(0011), Cmd:Talk(11), Register0(00)
place_bit0(); // Stopbit(0)
if (!wait_data_hi(500)) { // Service Request(310us Adjustable Keyboard): just ignored
send_byte(device | 0x0C); // Addr:Keyboard(0010)/Mouse(0011), Cmd:Talk(11), Register0(00)
place_bit0(); // Stopbit(0)
if (!wait_data_hi(500)) { // Service Request(310us Adjustable Keyboard): just ignored
sei();
return -30; // something wrong
return -30; // something wrong
}
if (!wait_data_lo(500)) { // Tlt/Stop to Start(140-260us)
if (!wait_data_lo(500)) { // Tlt/Stop to Start(140-260us)
sei();
return 0; // No data to send
return 0; // No data to send
}
uint8_t n = 17; // start bit + 16 data bits
uint8_t n = 17; // start bit + 16 data bits
do {
uint8_t lo = (uint8_t) wait_data_hi(130);
if (!lo)
goto error;
uint8_t hi = (uint8_t) wait_data_lo(lo);
if (!hi)
goto error;
uint8_t lo = (uint8_t)wait_data_hi(130);
if (!lo) goto error;
uint8_t hi = (uint8_t)wait_data_lo(lo);
if (!hi) goto error;
hi = lo - hi;
lo = 130 - lo;
data <<= 1;
if (lo < hi) {
data |= 1;
}
else if (n == 17) {
} else if (n == 17) {
sei();
return -20;
}
}
while ( --n );
} while (--n);
// Stop bit can't be checked normally since it could have service request lenghtening
// and its high state never goes low.
@ -197,76 +175,66 @@ error:
return -n;
}
void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l)
{
void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l) {
cli();
attention();
send_byte(cmd);
place_bit0(); // Stopbit(0)
_delay_us(200); // Tlt/Stop to Start
place_bit1(); // Startbit(1)
send_byte(data_h);
place_bit0(); // Stopbit(0)
_delay_us(200); // Tlt/Stop to Start
place_bit1(); // Startbit(1)
send_byte(data_h);
send_byte(data_l);
place_bit0(); // Stopbit(0);
place_bit0(); // Stopbit(0);
sei();
}
// send state of LEDs
void adb_host_kbd_led(uint8_t led)
{
void adb_host_kbd_led(uint8_t led) {
// Addr:Keyboard(0010), Cmd:Listen(10), Register2(10)
// send upper byte (not used)
// send lower byte (bit2: ScrollLock, bit1: CapsLock, bit0:
adb_host_listen(0x2A,0,led&0x07);
adb_host_listen(0x2A, 0, led & 0x07);
}
#ifdef ADB_PSW_BIT
static inline void psw_lo()
{
ADB_DDR |= (1<<ADB_PSW_BIT);
ADB_PORT &= ~(1<<ADB_PSW_BIT);
static inline void psw_lo() {
ADB_DDR |= (1 << ADB_PSW_BIT);
ADB_PORT &= ~(1 << ADB_PSW_BIT);
}
static inline void psw_hi()
{
ADB_PORT |= (1<<ADB_PSW_BIT);
ADB_DDR &= ~(1<<ADB_PSW_BIT);
static inline void psw_hi() {
ADB_PORT |= (1 << ADB_PSW_BIT);
ADB_DDR &= ~(1 << ADB_PSW_BIT);
}
static inline bool psw_in()
{
ADB_PORT |= (1<<ADB_PSW_BIT);
ADB_DDR &= ~(1<<ADB_PSW_BIT);
return ADB_PIN&(1<<ADB_PSW_BIT);
static inline bool psw_in() {
ADB_PORT |= (1 << ADB_PSW_BIT);
ADB_DDR &= ~(1 << ADB_PSW_BIT);
return ADB_PIN & (1 << ADB_PSW_BIT);
}
#endif
static inline void attention(void)
{
static inline void attention(void) {
data_lo();
_delay_us(800-35); // bit1 holds lo for 35 more
_delay_us(800 - 35); // bit1 holds lo for 35 more
place_bit1();
}
static inline void place_bit0(void)
{
static inline void place_bit0(void) {
data_lo();
_delay_us(65);
data_hi();
_delay_us(35);
}
static inline void place_bit1(void)
{
static inline void place_bit1(void) {
data_lo();
_delay_us(35);
data_hi();
_delay_us(65);
}
static inline void send_byte(uint8_t data)
{
static inline void send_byte(uint8_t data) {
for (int i = 0; i < 8; i++) {
if (data&(0x80>>i))
if (data & (0x80 >> i))
place_bit1();
else
place_bit0();
@ -275,29 +243,22 @@ static inline void send_byte(uint8_t data)
// These are carefully coded to take 6 cycles of overhead.
// inline asm approach became too convoluted
static inline uint16_t wait_data_lo(uint16_t us)
{
static inline uint16_t wait_data_lo(uint16_t us) {
do {
if ( !data_in() )
break;
if (!data_in()) break;
_delay_us(1 - (6 * 1000000.0 / F_CPU));
}
while ( --us );
} while (--us);
return us;
}
static inline uint16_t wait_data_hi(uint16_t us)
{
static inline uint16_t wait_data_hi(uint16_t us) {
do {
if ( data_in() )
break;
if (data_in()) break;
_delay_us(1 - (6 * 1000000.0 / F_CPU));
}
while ( --us );
} while (--us);
return us;
}
/*
ADB Protocol
============
@ -375,7 +336,7 @@ Commands
A A A A 1 1 R R Talk(read from a device)
The command to read keycodes from keyboard is 0x2C which
consist of keyboard address 2 and Talk against register 0.
consist of keyboard address 2 and Talk against register 0.
Address:
2: keyboard
@ -457,7 +418,7 @@ Keyboard Data(Register0)
Keyboard LEDs & state of keys(Register2)
This register hold current state of three LEDs and nine keys.
The state of LEDs can be changed by sending Listen command.
1514 . . . . . . 7 6 5 . 3 2 1 0
| | | | | | | | | | | | | | | +- LED1(NumLock)
| | | | | | | | | | | | | | +--- LED2(CapsLock)

View file

@ -41,16 +41,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdint.h>
#include <stdbool.h>
#if !(defined(ADB_PORT) && \
defined(ADB_PIN) && \
defined(ADB_DDR) && \
defined(ADB_DATA_BIT))
# error "ADB port setting is required in config.h"
#if !(defined(ADB_PORT) && defined(ADB_PIN) && defined(ADB_DDR) && defined(ADB_DATA_BIT))
# error "ADB port setting is required in config.h"
#endif
#define ADB_POWER 0x7F
#define ADB_CAPS 0x39
#define ADB_POWER 0x7F
#define ADB_CAPS 0x39
// ADB host
void adb_host_init(void);
@ -62,5 +58,4 @@ void adb_host_kbd_led(uint8_t led);
void adb_mouse_task(void);
void adb_mouse_init(void);
#endif

View file

@ -24,76 +24,92 @@ uint16_t v_con_2;
uint16_t v_con_1_boot;
uint16_t v_con_2_boot;
void ADC0_clock_init(void)
{
void ADC0_clock_init(void) {
DBGC(DC_ADC0_CLOCK_INIT_BEGIN);
MCLK->APBDMASK.bit.ADC0_ = 1; //ADC0 Clock Enable
MCLK->APBDMASK.bit.ADC0_ = 1; // ADC0 Clock Enable
GCLK->PCHCTRL[ADC0_GCLK_ID].bit.GEN = GEN_OSC0; //Select generator clock
GCLK->PCHCTRL[ADC0_GCLK_ID].bit.CHEN = 1; //Enable peripheral clock
GCLK->PCHCTRL[ADC0_GCLK_ID].bit.GEN = GEN_OSC0; // Select generator clock
GCLK->PCHCTRL[ADC0_GCLK_ID].bit.CHEN = 1; // Enable peripheral clock
DBGC(DC_ADC0_CLOCK_INIT_COMPLETE);
}
void ADC0_init(void)
{
void ADC0_init(void) {
DBGC(DC_ADC0_INIT_BEGIN);
//MCU
PORT->Group[1].DIRCLR.reg = 1 << 0; //PB00 as input 5V
PORT->Group[1].DIRCLR.reg = 1 << 1; //PB01 as input CON2
PORT->Group[1].DIRCLR.reg = 1 << 2; //PB02 as input CON1
PORT->Group[1].PMUX[0].bit.PMUXE = 1; //PB00 mux select B ADC 5V
PORT->Group[1].PMUX[0].bit.PMUXO = 1; //PB01 mux select B ADC CON2
PORT->Group[1].PMUX[1].bit.PMUXE = 1; //PB02 mux select B ADC CON1
PORT->Group[1].PINCFG[0].bit.PMUXEN = 1; //PB01 mux ADC Enable 5V
PORT->Group[1].PINCFG[1].bit.PMUXEN = 1; //PB01 mux ADC Enable CON2
PORT->Group[1].PINCFG[2].bit.PMUXEN = 1; //PB02 mux ADC Enable CON1
// MCU
PORT->Group[1].DIRCLR.reg = 1 << 0; // PB00 as input 5V
PORT->Group[1].DIRCLR.reg = 1 << 1; // PB01 as input CON2
PORT->Group[1].DIRCLR.reg = 1 << 2; // PB02 as input CON1
PORT->Group[1].PMUX[0].bit.PMUXE = 1; // PB00 mux select B ADC 5V
PORT->Group[1].PMUX[0].bit.PMUXO = 1; // PB01 mux select B ADC CON2
PORT->Group[1].PMUX[1].bit.PMUXE = 1; // PB02 mux select B ADC CON1
PORT->Group[1].PINCFG[0].bit.PMUXEN = 1; // PB01 mux ADC Enable 5V
PORT->Group[1].PINCFG[1].bit.PMUXEN = 1; // PB01 mux ADC Enable CON2
PORT->Group[1].PINCFG[2].bit.PMUXEN = 1; // PB02 mux ADC Enable CON1
//ADC
// ADC
ADC0->CTRLA.bit.SWRST = 1;
while (ADC0->SYNCBUSY.bit.SWRST) { DBGC(DC_ADC0_SWRST_SYNCING_1); }
while (ADC0->CTRLA.bit.SWRST) { DBGC(DC_ADC0_SWRST_SYNCING_2); }
while (ADC0->SYNCBUSY.bit.SWRST) {
DBGC(DC_ADC0_SWRST_SYNCING_1);
}
while (ADC0->CTRLA.bit.SWRST) {
DBGC(DC_ADC0_SWRST_SYNCING_2);
}
//Clock divide
// Clock divide
ADC0->CTRLA.bit.PRESCALER = ADC_CTRLA_PRESCALER_DIV2_Val;
//Averaging
// Averaging
ADC0->AVGCTRL.bit.SAMPLENUM = ADC_AVGCTRL_SAMPLENUM_4_Val;
while (ADC0->SYNCBUSY.bit.AVGCTRL) { DBGC(DC_ADC0_AVGCTRL_SYNCING_1); }
if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_1_Val) ADC0->AVGCTRL.bit.ADJRES = 0;
else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_2_Val) ADC0->AVGCTRL.bit.ADJRES = 1;
else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_4_Val) ADC0->AVGCTRL.bit.ADJRES = 2;
else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_8_Val) ADC0->AVGCTRL.bit.ADJRES = 3;
else ADC0->AVGCTRL.bit.ADJRES = 4;
while (ADC0->SYNCBUSY.bit.AVGCTRL) { DBGC(DC_ADC0_AVGCTRL_SYNCING_2); }
while (ADC0->SYNCBUSY.bit.AVGCTRL) {
DBGC(DC_ADC0_AVGCTRL_SYNCING_1);
}
if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_1_Val)
ADC0->AVGCTRL.bit.ADJRES = 0;
else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_2_Val)
ADC0->AVGCTRL.bit.ADJRES = 1;
else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_4_Val)
ADC0->AVGCTRL.bit.ADJRES = 2;
else if (ADC0->AVGCTRL.bit.SAMPLENUM == ADC_AVGCTRL_SAMPLENUM_8_Val)
ADC0->AVGCTRL.bit.ADJRES = 3;
else
ADC0->AVGCTRL.bit.ADJRES = 4;
while (ADC0->SYNCBUSY.bit.AVGCTRL) {
DBGC(DC_ADC0_AVGCTRL_SYNCING_2);
}
//Settling
ADC0->SAMPCTRL.bit.SAMPLEN = 45; //Sampling Time Length: 1-63, 1 ADC CLK per
while (ADC0->SYNCBUSY.bit.SAMPCTRL) { DBGC(DC_ADC0_SAMPCTRL_SYNCING_1); }
// Settling
ADC0->SAMPCTRL.bit.SAMPLEN = 45; // Sampling Time Length: 1-63, 1 ADC CLK per
while (ADC0->SYNCBUSY.bit.SAMPCTRL) {
DBGC(DC_ADC0_SAMPCTRL_SYNCING_1);
}
//Load factory calibration data
ADC0->CALIB.bit.BIASCOMP = ((*(uint32_t *)ADC0_FUSES_BIASCOMP_ADDR) & ADC0_FUSES_BIASCOMP_Msk) >> ADC0_FUSES_BIASCOMP_Pos;
ADC0->CALIB.bit.BIASR2R = ((*(uint32_t *)ADC0_FUSES_BIASR2R_ADDR) & ADC0_FUSES_BIASR2R_Msk) >> ADC0_FUSES_BIASR2R_Pos;
// Load factory calibration data
ADC0->CALIB.bit.BIASCOMP = ((*(uint32_t *)ADC0_FUSES_BIASCOMP_ADDR) & ADC0_FUSES_BIASCOMP_Msk) >> ADC0_FUSES_BIASCOMP_Pos;
ADC0->CALIB.bit.BIASR2R = ((*(uint32_t *)ADC0_FUSES_BIASR2R_ADDR) & ADC0_FUSES_BIASR2R_Msk) >> ADC0_FUSES_BIASR2R_Pos;
ADC0->CALIB.bit.BIASREFBUF = ((*(uint32_t *)ADC0_FUSES_BIASREFBUF_ADDR) & ADC0_FUSES_BIASREFBUF_Msk) >> ADC0_FUSES_BIASREFBUF_Pos;
//Enable
// Enable
ADC0->CTRLA.bit.ENABLE = 1;
while (ADC0->SYNCBUSY.bit.ENABLE) { DBGC(DC_ADC0_ENABLE_SYNCING_1); }
while (ADC0->SYNCBUSY.bit.ENABLE) {
DBGC(DC_ADC0_ENABLE_SYNCING_1);
}
DBGC(DC_ADC0_INIT_COMPLETE);
}
uint16_t adc_get(uint8_t muxpos)
{
uint16_t adc_get(uint8_t muxpos) {
ADC0->INPUTCTRL.bit.MUXPOS = muxpos;
while (ADC0->SYNCBUSY.bit.INPUTCTRL) {}
while (ADC0->SYNCBUSY.bit.INPUTCTRL) {
}
ADC0->SWTRIG.bit.START = 1;
while (ADC0->SYNCBUSY.bit.SWTRIG) {}
while (!ADC0->INTFLAG.bit.RESRDY) {}
while (ADC0->SYNCBUSY.bit.SWTRIG) {
}
while (!ADC0->INTFLAG.bit.RESRDY) {
}
return ADC0->RESULT.reg;
}

View file

@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _ADC_H_
#define _ADC_H_
#define ADC_5V_START_LEVEL 2365
#define ADC_5V_START_LEVEL 2365
#define ADC_5V ADC_INPUTCTRL_MUXPOS_AIN12_Val
#define ADC_CON1 ADC_INPUTCTRL_MUXPOS_AIN14_Val
#define ADC_CON2 ADC_INPUTCTRL_MUXPOS_AIN13_Val
#define ADC_5V ADC_INPUTCTRL_MUXPOS_AIN12_Val
#define ADC_CON1 ADC_INPUTCTRL_MUXPOS_AIN14_Val
#define ADC_CON2 ADC_INPUTCTRL_MUXPOS_AIN13_Val
extern uint16_t v_5v;
extern uint16_t v_5v_avg;
@ -34,4 +34,4 @@ extern uint16_t v_con_2_boot;
void ADC0_clock_init(void);
void ADC0_init(void);
#endif //_ADC_H_
#endif //_ADC_H_

View file

@ -33,17 +33,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef MD_BOOTLOADER
#include "main_arm_atsam.h"
#ifdef RGB_MATRIX_ENABLE
#include "led_matrix.h"
#include "rgb_matrix.h"
#endif
#include "issi3733_driver.h"
#include "./usb/compiler.h"
#include "./usb/udc.h"
#include "./usb/udi_cdc.h"
# include "main_arm_atsam.h"
# ifdef RGB_MATRIX_ENABLE
# include "led_matrix.h"
# include "rgb_matrix.h"
# endif
# include "issi3733_driver.h"
# include "./usb/compiler.h"
# include "./usb/udc.h"
# include "./usb/udi_cdc.h"
#endif //MD_BOOTLOADER
#endif //_ARM_ATSAM_PROTOCOL_H_
#endif // MD_BOOTLOADER
#endif //_ARM_ATSAM_PROTOCOL_H_

View file

@ -19,83 +19,105 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <string.h>
volatile clk_t system_clks;
volatile clk_t system_clks;
volatile uint64_t ms_clk;
uint32_t usec_delay_mult;
#define USEC_DELAY_LOOP_CYCLES 3 //Sum of instruction cycles in us delay loop
uint32_t usec_delay_mult;
#define USEC_DELAY_LOOP_CYCLES 3 // Sum of instruction cycles in us delay loop
const uint32_t sercom_apbbase[] = {(uint32_t)SERCOM0,(uint32_t)SERCOM1,(uint32_t)SERCOM2,(uint32_t)SERCOM3,(uint32_t)SERCOM4,(uint32_t)SERCOM5};
const uint8_t sercom_pchan[] = {7, 8, 23, 24, 34, 35};
const uint32_t sercom_apbbase[] = {(uint32_t)SERCOM0, (uint32_t)SERCOM1, (uint32_t)SERCOM2, (uint32_t)SERCOM3, (uint32_t)SERCOM4, (uint32_t)SERCOM5};
const uint8_t sercom_pchan[] = {7, 8, 23, 24, 34, 35};
#define USE_DPLL_IND 0
#define USE_DPLL_DEF GCLK_SOURCE_DPLL0
#define USE_DPLL_IND 0
#define USE_DPLL_DEF GCLK_SOURCE_DPLL0
void CLK_oscctrl_init(void)
{
void CLK_oscctrl_init(void) {
Oscctrl *posctrl = OSCCTRL;
Gclk *pgclk = GCLK;
Gclk * pgclk = GCLK;
DBGC(DC_CLK_OSC_INIT_BEGIN);
//default setup on por
system_clks.freq_dfll = FREQ_DFLL_DEFAULT;
// default setup on por
system_clks.freq_dfll = FREQ_DFLL_DEFAULT;
system_clks.freq_gclk[0] = system_clks.freq_dfll;
//configure and startup 16MHz xosc0
posctrl->XOSCCTRL[0].bit.ENABLE = 0;
posctrl->XOSCCTRL[0].bit.STARTUP = 0xD;
posctrl->XOSCCTRL[0].bit.ENALC = 1;
posctrl->XOSCCTRL[0].bit.IMULT = 5;
posctrl->XOSCCTRL[0].bit.IPTAT = 3;
// configure and startup 16MHz xosc0
posctrl->XOSCCTRL[0].bit.ENABLE = 0;
posctrl->XOSCCTRL[0].bit.STARTUP = 0xD;
posctrl->XOSCCTRL[0].bit.ENALC = 1;
posctrl->XOSCCTRL[0].bit.IMULT = 5;
posctrl->XOSCCTRL[0].bit.IPTAT = 3;
posctrl->XOSCCTRL[0].bit.ONDEMAND = 0;
posctrl->XOSCCTRL[0].bit.XTALEN = 1;
posctrl->XOSCCTRL[0].bit.ENABLE = 1;
while (posctrl->STATUS.bit.XOSCRDY0 == 0) { DBGC(DC_CLK_OSC_INIT_XOSC0_SYNC); }
posctrl->XOSCCTRL[0].bit.XTALEN = 1;
posctrl->XOSCCTRL[0].bit.ENABLE = 1;
while (posctrl->STATUS.bit.XOSCRDY0 == 0) {
DBGC(DC_CLK_OSC_INIT_XOSC0_SYNC);
}
system_clks.freq_xosc0 = FREQ_XOSC0;
//configure and startup DPLL
// configure and startup DPLL
posctrl->Dpll[USE_DPLL_IND].DPLLCTRLA.bit.ENABLE = 0;
while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_DISABLE); }
posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.REFCLK = 2; //select XOSC0 (16MHz)
posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.DIV = 7; //16 MHz / (2 * (7 + 1)) = 1 MHz
posctrl->Dpll[USE_DPLL_IND].DPLLRATIO.bit.LDR = PLL_RATIO; //1 MHz * (PLL_RATIO(47) + 1) = 48MHz
while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.DPLLRATIO) { DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_RATIO); }
while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.ENABLE) {
DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_DISABLE);
}
posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.REFCLK = 2; // select XOSC0 (16MHz)
posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.DIV = 7; // 16 MHz / (2 * (7 + 1)) = 1 MHz
posctrl->Dpll[USE_DPLL_IND].DPLLRATIO.bit.LDR = PLL_RATIO; // 1 MHz * (PLL_RATIO(47) + 1) = 48MHz
while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.DPLLRATIO) {
DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_RATIO);
}
posctrl->Dpll[USE_DPLL_IND].DPLLCTRLA.bit.ONDEMAND = 0;
posctrl->Dpll[USE_DPLL_IND].DPLLCTRLA.bit.ENABLE = 1;
while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_ENABLE); }
while (posctrl->Dpll[USE_DPLL_IND].DPLLSTATUS.bit.LOCK == 0) { DBGC(DC_CLK_OSC_INIT_DPLL_WAIT_LOCK); }
while (posctrl->Dpll[USE_DPLL_IND].DPLLSTATUS.bit.CLKRDY == 0) { DBGC(DC_CLK_OSC_INIT_DPLL_WAIT_CLKRDY); }
posctrl->Dpll[USE_DPLL_IND].DPLLCTRLA.bit.ENABLE = 1;
while (posctrl->Dpll[USE_DPLL_IND].DPLLSYNCBUSY.bit.ENABLE) {
DBGC(DC_CLK_OSC_INIT_DPLL_SYNC_ENABLE);
}
while (posctrl->Dpll[USE_DPLL_IND].DPLLSTATUS.bit.LOCK == 0) {
DBGC(DC_CLK_OSC_INIT_DPLL_WAIT_LOCK);
}
while (posctrl->Dpll[USE_DPLL_IND].DPLLSTATUS.bit.CLKRDY == 0) {
DBGC(DC_CLK_OSC_INIT_DPLL_WAIT_CLKRDY);
}
system_clks.freq_dpll[0] = (system_clks.freq_xosc0 / 2 / (posctrl->Dpll[USE_DPLL_IND].DPLLCTRLB.bit.DIV + 1)) * (posctrl->Dpll[USE_DPLL_IND].DPLLRATIO.bit.LDR + 1);
//change gclk0 to DPLL
// change gclk0 to DPLL
pgclk->GENCTRL[GEN_DPLL0].bit.SRC = USE_DPLL_DEF;
while (pgclk->SYNCBUSY.bit.GENCTRL0) { DBGC(DC_CLK_OSC_INIT_GCLK_SYNC_GENCTRL0); }
while (pgclk->SYNCBUSY.bit.GENCTRL0) {
DBGC(DC_CLK_OSC_INIT_GCLK_SYNC_GENCTRL0);
}
system_clks.freq_gclk[0] = system_clks.freq_dpll[0];
usec_delay_mult = system_clks.freq_gclk[0] / (USEC_DELAY_LOOP_CYCLES * 1000000);
if (usec_delay_mult < 1) usec_delay_mult = 1; //Never allow a multiplier of zero
if (usec_delay_mult < 1) usec_delay_mult = 1; // Never allow a multiplier of zero
DBGC(DC_CLK_OSC_INIT_COMPLETE);
}
//configure for 1MHz (1 usec timebase)
//call CLK_set_gclk_freq(GEN_TC45, FREQ_TC45_DEFAULT);
uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq)
{
// configure for 1MHz (1 usec timebase)
// call CLK_set_gclk_freq(GEN_TC45, FREQ_TC45_DEFAULT);
uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq) {
Gclk *pgclk = GCLK;
DBGC(DC_CLK_SET_GCLK_FREQ_BEGIN);
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_1); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_1);
}
pgclk->GENCTRL[gclkn].bit.SRC = USE_DPLL_DEF;
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_2); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_2);
}
pgclk->GENCTRL[gclkn].bit.DIV = (uint8_t)(system_clks.freq_dpll[0] / freq);
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_3); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_3);
}
pgclk->GENCTRL[gclkn].bit.DIVSEL = 0;
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_4); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_4);
}
pgclk->GENCTRL[gclkn].bit.GENEN = 1;
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_5); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_SET_GCLK_FREQ_SYNC_5);
}
system_clks.freq_gclk[gclkn] = system_clks.freq_dpll[0] / pgclk->GENCTRL[gclkn].bit.DIV;
DBGC(DC_CLK_SET_GCLK_FREQ_COMPLETE);
@ -103,29 +125,37 @@ uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq)
return system_clks.freq_gclk[gclkn];
}
void CLK_init_osc(void)
{
void CLK_init_osc(void) {
uint8_t gclkn = GEN_OSC0;
Gclk *pgclk = GCLK;
Gclk * pgclk = GCLK;
DBGC(DC_CLK_INIT_OSC_BEGIN);
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_1); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_INIT_OSC_SYNC_1);
}
pgclk->GENCTRL[gclkn].bit.SRC = GCLK_SOURCE_XOSC0;
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_2); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_INIT_OSC_SYNC_2);
}
pgclk->GENCTRL[gclkn].bit.DIV = 1;
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_3); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_INIT_OSC_SYNC_3);
}
pgclk->GENCTRL[gclkn].bit.DIVSEL = 0;
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_4); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_INIT_OSC_SYNC_4);
}
pgclk->GENCTRL[gclkn].bit.GENEN = 1;
while (pgclk->SYNCBUSY.vec.GENCTRL) { DBGC(DC_CLK_INIT_OSC_SYNC_5); }
while (pgclk->SYNCBUSY.vec.GENCTRL) {
DBGC(DC_CLK_INIT_OSC_SYNC_5);
}
system_clks.freq_gclk[gclkn] = system_clks.freq_xosc0;
DBGC(DC_CLK_INIT_OSC_COMPLETE);
}
void CLK_reset_time(void)
{
void CLK_reset_time(void) {
Tc *ptc4 = TC4;
Tc *ptc0 = TC0;
@ -133,72 +163,85 @@ void CLK_reset_time(void)
DBGC(DC_CLK_RESET_TIME_BEGIN);
//stop counters
// stop counters
ptc4->COUNT16.CTRLA.bit.ENABLE = 0;
while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {}
while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {
}
ptc0->COUNT32.CTRLA.bit.ENABLE = 0;
while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {}
//zero counters
while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {
}
// zero counters
ptc4->COUNT16.COUNT.reg = 0;
while (ptc4->COUNT16.SYNCBUSY.bit.COUNT) {}
while (ptc4->COUNT16.SYNCBUSY.bit.COUNT) {
}
ptc0->COUNT32.COUNT.reg = 0;
while (ptc0->COUNT32.SYNCBUSY.bit.COUNT) {}
//start counters
while (ptc0->COUNT32.SYNCBUSY.bit.COUNT) {
}
// start counters
ptc0->COUNT32.CTRLA.bit.ENABLE = 1;
while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {}
while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {
}
ptc4->COUNT16.CTRLA.bit.ENABLE = 1;
while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {}
while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {
}
DBGC(DC_CLK_RESET_TIME_COMPLETE);
}
void TC4_Handler()
{
if (TC4->COUNT16.INTFLAG.bit.MC0)
{
void TC4_Handler() {
if (TC4->COUNT16.INTFLAG.bit.MC0) {
TC4->COUNT16.INTFLAG.reg = TC_INTENCLR_MC0;
ms_clk++;
}
}
uint32_t CLK_enable_timebase(void)
{
Gclk *pgclk = GCLK;
Mclk *pmclk = MCLK;
Tc *ptc4 = TC4;
Tc *ptc0 = TC0;
uint32_t CLK_enable_timebase(void) {
Gclk * pgclk = GCLK;
Mclk * pmclk = MCLK;
Tc * ptc4 = TC4;
Tc * ptc0 = TC0;
Evsys *pevsys = EVSYS;
DBGC(DC_CLK_ENABLE_TIMEBASE_BEGIN);
//gclk2 highspeed time base
// gclk2 highspeed time base
CLK_set_gclk_freq(GEN_TC45, FREQ_TC45_DEFAULT);
CLK_init_osc();
//unmask TC4, sourcegclk2 to TC4
pmclk->APBCMASK.bit.TC4_ = 1;
pgclk->PCHCTRL[TC4_GCLK_ID].bit.GEN = GEN_TC45;
// unmask TC4, sourcegclk2 to TC4
pmclk->APBCMASK.bit.TC4_ = 1;
pgclk->PCHCTRL[TC4_GCLK_ID].bit.GEN = GEN_TC45;
pgclk->PCHCTRL[TC4_GCLK_ID].bit.CHEN = 1;
//configure TC4
// configure TC4
DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_BEGIN);
ptc4->COUNT16.CTRLA.bit.ENABLE = 0;
while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_DISABLE); }
while (ptc4->COUNT16.SYNCBUSY.bit.ENABLE) {
DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_DISABLE);
}
ptc4->COUNT16.CTRLA.bit.SWRST = 1;
while (ptc4->COUNT16.SYNCBUSY.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_1); }
while (ptc4->COUNT16.CTRLA.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_2); }
while (ptc4->COUNT16.SYNCBUSY.bit.SWRST) {
DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_1);
}
while (ptc4->COUNT16.CTRLA.bit.SWRST) {
DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_2);
}
//CTRLA defaults
//CTRLB as default, counting up
// CTRLA defaults
// CTRLB as default, counting up
ptc4->COUNT16.CTRLBCLR.reg = 5;
while (ptc4->COUNT16.SYNCBUSY.bit.CTRLB) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CLTRB); }
while (ptc4->COUNT16.SYNCBUSY.bit.CTRLB) {
DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CLTRB);
}
ptc4->COUNT16.CC[0].reg = 999;
while (ptc4->COUNT16.SYNCBUSY.bit.CC0) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CC0); }
//ptc4->COUNT16.DBGCTRL.bit.DBGRUN = 1;
while (ptc4->COUNT16.SYNCBUSY.bit.CC0) {
DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CC0);
}
// ptc4->COUNT16.DBGCTRL.bit.DBGRUN = 1;
//wave mode
ptc4->COUNT16.WAVE.bit.WAVEGEN = 1; //MFRQ match frequency mode, toggle each CC match
//generate event for next stage
// wave mode
ptc4->COUNT16.WAVE.bit.WAVEGEN = 1; // MFRQ match frequency mode, toggle each CC match
// generate event for next stage
ptc4->COUNT16.EVCTRL.bit.MCEO0 = 1;
NVIC_EnableIRQ(TC4_IRQn);
@ -206,39 +249,45 @@ uint32_t CLK_enable_timebase(void)
DBGC(DC_CLK_ENABLE_TIMEBASE_TC4_COMPLETE);
//unmask TC0,1, sourcegclk2 to TC0,1
pmclk->APBAMASK.bit.TC0_ = 1;
pgclk->PCHCTRL[TC0_GCLK_ID].bit.GEN = GEN_TC45;
// unmask TC0,1, sourcegclk2 to TC0,1
pmclk->APBAMASK.bit.TC0_ = 1;
pgclk->PCHCTRL[TC0_GCLK_ID].bit.GEN = GEN_TC45;
pgclk->PCHCTRL[TC0_GCLK_ID].bit.CHEN = 1;
pmclk->APBAMASK.bit.TC1_ = 1;
pgclk->PCHCTRL[TC1_GCLK_ID].bit.GEN = GEN_TC45;
pmclk->APBAMASK.bit.TC1_ = 1;
pgclk->PCHCTRL[TC1_GCLK_ID].bit.GEN = GEN_TC45;
pgclk->PCHCTRL[TC1_GCLK_ID].bit.CHEN = 1;
//configure TC0
// configure TC0
DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_BEGIN);
ptc0->COUNT32.CTRLA.bit.ENABLE = 0;
while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_DISABLE); }
while (ptc0->COUNT32.SYNCBUSY.bit.ENABLE) {
DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_DISABLE);
}
ptc0->COUNT32.CTRLA.bit.SWRST = 1;
while (ptc0->COUNT32.SYNCBUSY.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_1); }
while (ptc0->COUNT32.CTRLA.bit.SWRST) { DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_2); }
//CTRLA as default
ptc0->COUNT32.CTRLA.bit.MODE = 2; //32 bit mode
ptc0->COUNT32.EVCTRL.bit.TCEI = 1; //enable incoming events
ptc0->COUNT32.EVCTRL.bit.EVACT = 2 ; //count events
while (ptc0->COUNT32.SYNCBUSY.bit.SWRST) {
DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_1);
}
while (ptc0->COUNT32.CTRLA.bit.SWRST) {
DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_2);
}
// CTRLA as default
ptc0->COUNT32.CTRLA.bit.MODE = 2; // 32 bit mode
ptc0->COUNT32.EVCTRL.bit.TCEI = 1; // enable incoming events
ptc0->COUNT32.EVCTRL.bit.EVACT = 2; // count events
DBGC(DC_CLK_ENABLE_TIMEBASE_TC0_COMPLETE);
DBGC(DC_CLK_ENABLE_TIMEBASE_EVSYS_BEGIN);
//configure event system
pmclk->APBBMASK.bit.EVSYS_ = 1;
pgclk->PCHCTRL[EVSYS_GCLK_ID_0].bit.GEN = GEN_TC45;
// configure event system
pmclk->APBBMASK.bit.EVSYS_ = 1;
pgclk->PCHCTRL[EVSYS_GCLK_ID_0].bit.GEN = GEN_TC45;
pgclk->PCHCTRL[EVSYS_GCLK_ID_0].bit.CHEN = 1;
pevsys->USER[44].reg = EVSYS_ID_USER_PORT_EV_0; //TC0 will get event channel 0
pevsys->Channel[0].CHANNEL.bit.EDGSEL = EVSYS_CHANNEL_EDGSEL_RISING_EDGE_Val; //Rising edge
pevsys->Channel[0].CHANNEL.bit.PATH = EVSYS_CHANNEL_PATH_SYNCHRONOUS_Val; //Synchronous
pevsys->Channel[0].CHANNEL.bit.EVGEN = EVSYS_ID_GEN_TC4_MCX_0; //TC4 MC0
pevsys->USER[44].reg = EVSYS_ID_USER_PORT_EV_0; // TC0 will get event channel 0
pevsys->Channel[0].CHANNEL.bit.EDGSEL = EVSYS_CHANNEL_EDGSEL_RISING_EDGE_Val; // Rising edge
pevsys->Channel[0].CHANNEL.bit.PATH = EVSYS_CHANNEL_PATH_SYNCHRONOUS_Val; // Synchronous
pevsys->Channel[0].CHANNEL.bit.EVGEN = EVSYS_ID_GEN_TC4_MCX_0; // TC4 MC0
DBGC(DC_CLK_ENABLE_TIMEBASE_EVSYS_COMPLETE);
@ -251,34 +300,29 @@ uint32_t CLK_enable_timebase(void)
return 0;
}
void CLK_delay_us(uint32_t usec)
{
asm (
"CBZ R0, return\n\t" //If usec == 0, branch to return label
void CLK_delay_us(uint32_t usec) {
asm("CBZ R0, return\n\t" // If usec == 0, branch to return label
);
asm (
"MULS R0, %0\n\t" //Multiply R0(usec) by usec_delay_mult and store in R0
".balign 16\n\t" //Ensure loop is aligned for fastest performance
"loop: SUBS R0, #1\n\t" //Subtract 1 from R0 and update flags (1 cycle)
"BNE loop\n\t" //Branch if non-zero to loop label (2 cycles) NOTE: USEC_DELAY_LOOP_CYCLES is the sum of loop cycles
"return:\n\t" //Return label
: //No output registers
: "r" (usec_delay_mult) //For %0
asm("MULS R0, %0\n\t" // Multiply R0(usec) by usec_delay_mult and store in R0
".balign 16\n\t" // Ensure loop is aligned for fastest performance
"loop: SUBS R0, #1\n\t" // Subtract 1 from R0 and update flags (1 cycle)
"BNE loop\n\t" // Branch if non-zero to loop label (2 cycles) NOTE: USEC_DELAY_LOOP_CYCLES is the sum of loop cycles
"return:\n\t" // Return label
: // No output registers
: "r"(usec_delay_mult) // For %0
);
//Note: BX LR generated
// Note: BX LR generated
}
void CLK_delay_ms(uint64_t msec)
{
void CLK_delay_ms(uint64_t msec) {
msec += timer_read64();
while (msec > timer_read64()) {}
while (msec > timer_read64()) {
}
}
void clk_enable_sercom_apbmask(int sercomn)
{
void clk_enable_sercom_apbmask(int sercomn) {
Mclk *pmclk = MCLK;
switch (sercomn)
{
switch (sercomn) {
case 0:
pmclk->APBAMASK.bit.SERCOM0_ = 1;
break;
@ -296,26 +340,27 @@ void clk_enable_sercom_apbmask(int sercomn)
}
}
//call CLK_oscctrl_init first
//call CLK_set_spi_freq(CHAN_SERCOM_SPI, FREQ_SPI_DEFAULT);
uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq)
{
// call CLK_oscctrl_init first
// call CLK_set_spi_freq(CHAN_SERCOM_SPI, FREQ_SPI_DEFAULT);
uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq) {
DBGC(DC_CLK_SET_SPI_FREQ_BEGIN);
Gclk *pgclk = GCLK;
Gclk * pgclk = GCLK;
Sercom *psercom = (Sercom *)sercom_apbbase[sercomn];
clk_enable_sercom_apbmask(sercomn);
//all gclk0 for now
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
// all gclk0 for now
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.CHEN = 1;
psercom->I2CM.CTRLA.bit.SWRST = 1;
while (psercom->I2CM.SYNCBUSY.bit.SWRST) {}
while (psercom->I2CM.CTRLA.bit.SWRST) {}
while (psercom->I2CM.SYNCBUSY.bit.SWRST) {
}
while (psercom->I2CM.CTRLA.bit.SWRST) {
}
psercom->SPI.BAUD.reg = (uint8_t) (system_clks.freq_gclk[0]/2/freq-1);
system_clks.freq_spi = system_clks.freq_gclk[0]/2/(psercom->SPI.BAUD.reg+1);
psercom->SPI.BAUD.reg = (uint8_t)(system_clks.freq_gclk[0] / 2 / freq - 1);
system_clks.freq_spi = system_clks.freq_gclk[0] / 2 / (psercom->SPI.BAUD.reg + 1);
system_clks.freq_sercom[sercomn] = system_clks.freq_spi;
DBGC(DC_CLK_SET_SPI_FREQ_COMPLETE);
@ -323,26 +368,27 @@ uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq)
return system_clks.freq_spi;
}
//call CLK_oscctrl_init first
//call CLK_set_i2c0_freq(CHAN_SERCOM_I2C0, FREQ_I2C0_DEFAULT);
uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq)
{
// call CLK_oscctrl_init first
// call CLK_set_i2c0_freq(CHAN_SERCOM_I2C0, FREQ_I2C0_DEFAULT);
uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq) {
DBGC(DC_CLK_SET_I2C0_FREQ_BEGIN);
Gclk *pgclk = GCLK;
Gclk * pgclk = GCLK;
Sercom *psercom = (Sercom *)sercom_apbbase[sercomn];
clk_enable_sercom_apbmask(sercomn);
//all gclk0 for now
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
// all gclk0 for now
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.CHEN = 1;
psercom->I2CM.CTRLA.bit.SWRST = 1;
while (psercom->I2CM.SYNCBUSY.bit.SWRST) {}
while (psercom->I2CM.CTRLA.bit.SWRST) {}
while (psercom->I2CM.SYNCBUSY.bit.SWRST) {
}
while (psercom->I2CM.CTRLA.bit.SWRST) {
}
psercom->I2CM.BAUD.bit.BAUD = (uint8_t) (system_clks.freq_gclk[0]/2/freq-1);
system_clks.freq_i2c0 = system_clks.freq_gclk[0]/2/(psercom->I2CM.BAUD.bit.BAUD+1);
psercom->I2CM.BAUD.bit.BAUD = (uint8_t)(system_clks.freq_gclk[0] / 2 / freq - 1);
system_clks.freq_i2c0 = system_clks.freq_gclk[0] / 2 / (psercom->I2CM.BAUD.bit.BAUD + 1);
system_clks.freq_sercom[sercomn] = system_clks.freq_i2c0;
DBGC(DC_CLK_SET_I2C0_FREQ_COMPLETE);
@ -350,26 +396,27 @@ uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq)
return system_clks.freq_i2c0;
}
//call CLK_oscctrl_init first
//call CLK_set_i2c1_freq(CHAN_SERCOM_I2C1, FREQ_I2C1_DEFAULT);
uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq)
{
// call CLK_oscctrl_init first
// call CLK_set_i2c1_freq(CHAN_SERCOM_I2C1, FREQ_I2C1_DEFAULT);
uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq) {
DBGC(DC_CLK_SET_I2C1_FREQ_BEGIN);
Gclk *pgclk = GCLK;
Gclk * pgclk = GCLK;
Sercom *psercom = (Sercom *)sercom_apbbase[sercomn];
clk_enable_sercom_apbmask(sercomn);
//all gclk0 for now
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
// all gclk0 for now
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.GEN = 0;
pgclk->PCHCTRL[sercom_pchan[sercomn]].bit.CHEN = 1;
psercom->I2CM.CTRLA.bit.SWRST = 1;
while (psercom->I2CM.SYNCBUSY.bit.SWRST) {}
while (psercom->I2CM.CTRLA.bit.SWRST) {}
while (psercom->I2CM.SYNCBUSY.bit.SWRST) {
}
while (psercom->I2CM.CTRLA.bit.SWRST) {
}
psercom->I2CM.BAUD.bit.BAUD = (uint8_t) (system_clks.freq_gclk[0]/2/freq-10);
system_clks.freq_i2c1 = system_clks.freq_gclk[0]/2/(psercom->I2CM.BAUD.bit.BAUD+10);
psercom->I2CM.BAUD.bit.BAUD = (uint8_t)(system_clks.freq_gclk[0] / 2 / freq - 10);
system_clks.freq_i2c1 = system_clks.freq_gclk[0] / 2 / (psercom->I2CM.BAUD.bit.BAUD + 10);
system_clks.freq_sercom[sercomn] = system_clks.freq_i2c1;
DBGC(DC_CLK_SET_I2C1_FREQ_COMPLETE);
@ -377,15 +424,13 @@ uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq)
return system_clks.freq_i2c1;
}
void CLK_init(void)
{
void CLK_init(void) {
DBGC(DC_CLK_INIT_BEGIN);
memset((void *)&system_clks,0,sizeof(system_clks));
memset((void *)&system_clks, 0, sizeof(system_clks));
CLK_oscctrl_init();
CLK_enable_timebase();
DBGC(DC_CLK_INIT_COMPLETE);
}

View file

@ -20,20 +20,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef MD_BOOTLOADER
//From keyboard
#include "config_led.h"
#include "config.h"
// From keyboard
# include "config_led.h"
# include "config.h"
#endif //MD_BOOTLOADER
#endif // MD_BOOTLOADER
#define PLL_RATIO 47 //mcu frequency ((X+1)MHz)
#define FREQ_DFLL_DEFAULT 48000000 //DFLL frequency / usb clock
#define FREQ_SPI_DEFAULT 1000000 //spi to 595 shift regs
#define FREQ_I2C0_DEFAULT 100000 //i2c to hub
#define FREQ_I2C1_DEFAULT I2C_HZ //i2c to LED drivers
#define FREQ_TC45_DEFAULT 1000000 //1 usec resolution
#define PLL_RATIO 47 // mcu frequency ((X+1)MHz)
#define FREQ_DFLL_DEFAULT 48000000 // DFLL frequency / usb clock
#define FREQ_SPI_DEFAULT 1000000 // spi to 595 shift regs
#define FREQ_I2C0_DEFAULT 100000 // i2c to hub
#define FREQ_I2C1_DEFAULT I2C_HZ // i2c to LED drivers
#define FREQ_TC45_DEFAULT 1000000 // 1 usec resolution
//I2C1 Set ~Result PWM Time (2x Drivers)
// I2C1 Set ~Result PWM Time (2x Drivers)
// 1000000 1090000
// 900000 1000000 3.82ms
// 800000 860000
@ -42,20 +42,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// 580000 615000 6.08ms
// 500000 522000
#define FREQ_XOSC0 16000000
#define FREQ_XOSC0 16000000
#define CHAN_SERCOM_SPI 2 //shift regs
#define CHAN_SERCOM_I2C0 0 //hub
#define CHAN_SERCOM_I2C1 1 //led drivers
#define CHAN_SERCOM_UART 3 //debug util
#define CHAN_SERCOM_SPI 2 // shift regs
#define CHAN_SERCOM_I2C0 0 // hub
#define CHAN_SERCOM_I2C1 1 // led drivers
#define CHAN_SERCOM_UART 3 // debug util
//Generator clock channels
#define GEN_DPLL0 0
#define GEN_OSC0 1
#define GEN_TC45 2
// Generator clock channels
#define GEN_DPLL0 0
#define GEN_OSC0 1
#define GEN_TC45 2
#define SERCOM_COUNT 5
#define GCLK_COUNT 12
#define GCLK_COUNT 12
typedef struct clk_s {
uint32_t freq_dfll;
@ -70,20 +70,20 @@ typedef struct clk_s {
uint32_t freq_adc0;
} clk_t;
extern volatile clk_t system_clks;
extern volatile clk_t system_clks;
extern volatile uint64_t ms_clk;
void CLK_oscctrl_init(void);
void CLK_reset_time(void);
void CLK_oscctrl_init(void);
void CLK_reset_time(void);
uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq);
uint32_t CLK_enable_timebase(void);
uint64_t timer_read64(void);
void CLK_delay_us(uint32_t usec);
void CLK_delay_ms(uint64_t msec);
void CLK_delay_us(uint32_t usec);
void CLK_delay_ms(uint64_t msec);
uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq);
uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq);
uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq);
void CLK_init(void);
void CLK_init(void);
#endif // _CLKS_H_
#endif // _CLKS_H_

View file

@ -1,46 +1,50 @@
#include "d51_util.h"
static volatile uint32_t w;
//Display unsigned 32-bit number by port toggling DBG_1 (to view on a scope)
//Read as follows: 1230 = | | | | | | || (note zero is fast double toggle)
// Display unsigned 32-bit number by port toggling DBG_1 (to view on a scope)
// Read as follows: 1230 = | | | | | | || (note zero is fast double toggle)
#define DBG_PAUSE 5
void dbg_print(uint32_t x)
{
int8_t t;
void dbg_print(uint32_t x) {
int8_t t;
uint32_t n;
uint32_t p, p2;
if (x < 10) t = 0;
else if (x < 100) t = 1;
else if (x < 1000) t = 2;
else if (x < 10000) t = 3;
else if (x < 100000) t = 4;
else if (x < 1000000) t = 5;
else if (x < 10000000) t = 6;
else if (x < 100000000) t = 7;
else if (x < 1000000000) t = 8;
else t = 9;
if (x < 10)
t = 0;
else if (x < 100)
t = 1;
else if (x < 1000)
t = 2;
else if (x < 10000)
t = 3;
else if (x < 100000)
t = 4;
else if (x < 1000000)
t = 5;
else if (x < 10000000)
t = 6;
else if (x < 100000000)
t = 7;
else if (x < 1000000000)
t = 8;
else
t = 9;
while (t >= 0)
{
while (t >= 0) {
p2 = t;
p = 1;
p = 1;
while (p2--) p *= 10;
n = x / p;
x -= n * p;
if (!n)
{
if (!n) {
DBG_1_ON;
DBG_1_OFF;
DBG_1_ON;
DBG_1_OFF;
n--;
}
else
{
while (n > 0)
{
} else {
while (n > 0) {
DBG_1_ON;
DBG_1_OFF;
n--;
@ -50,68 +54,80 @@ void dbg_print(uint32_t x)
t--;
}
for (w = DBG_PAUSE; w; w--); //Long pause after number is complete
for (w = DBG_PAUSE; w; w--)
; // Long pause after number is complete
}
//Display unsigned 32-bit number through debug led
//Read as follows: 1230 = [*] [* *] [* * *] [**] (note zero is fast double flash)
// Display unsigned 32-bit number through debug led
// Read as follows: 1230 = [*] [* *] [* * *] [**] (note zero is fast double flash)
#define DLED_ONTIME 1000000
#define DLED_PAUSE 1500000
void dled_print(uint32_t x, uint8_t long_pause)
{
int8_t t;
void dled_print(uint32_t x, uint8_t long_pause) {
int8_t t;
uint32_t n;
uint32_t p, p2;
if (x < 10) t = 0;
else if (x < 100) t = 1;
else if (x < 1000) t = 2;
else if (x < 10000) t = 3;
else if (x < 100000) t = 4;
else if (x < 1000000) t = 5;
else if (x < 10000000) t = 6;
else if (x < 100000000) t = 7;
else if (x < 1000000000) t = 8;
else t = 9;
if (x < 10)
t = 0;
else if (x < 100)
t = 1;
else if (x < 1000)
t = 2;
else if (x < 10000)
t = 3;
else if (x < 100000)
t = 4;
else if (x < 1000000)
t = 5;
else if (x < 10000000)
t = 6;
else if (x < 100000000)
t = 7;
else if (x < 1000000000)
t = 8;
else
t = 9;
while (t >= 0)
{
while (t >= 0) {
p2 = t;
p = 1;
p = 1;
while (p2--) p *= 10;
n = x / p;
x -= n * p;
if (!n)
{
if (!n) {
DBG_LED_ON;
for (w = DLED_ONTIME / 4; w; w--);
for (w = DLED_ONTIME / 4; w; w--)
;
DBG_LED_OFF;
for (w = DLED_ONTIME / 4; w; w--);
for (w = DLED_ONTIME / 4; w; w--)
;
DBG_LED_ON;
for (w = DLED_ONTIME / 4; w; w--);
for (w = DLED_ONTIME / 4; w; w--)
;
DBG_LED_OFF;
for (w = DLED_ONTIME / 4; w; w--);
for (w = DLED_ONTIME / 4; w; w--)
;
n--;
}
else
{
while (n > 0)
{
} else {
while (n > 0) {
DBG_LED_ON;
for (w = DLED_ONTIME; w; w--);
for (w = DLED_ONTIME; w; w--)
;
DBG_LED_OFF;
for (w = DLED_ONTIME / 2; w; w--);
for (w = DLED_ONTIME / 2; w; w--)
;
n--;
}
}
for (w = DLED_PAUSE; w; w--);
for (w = DLED_PAUSE; w; w--)
;
t--;
}
if (long_pause)
{
for (w = DLED_PAUSE * 4; w; w--);
if (long_pause) {
for (w = DLED_PAUSE * 4; w; w--)
;
}
}
@ -119,103 +135,102 @@ void dled_print(uint32_t x, uint8_t long_pause)
volatile uint32_t debug_code;
//These macros are for compile time substitution
#define DEBUG_BOOT_TRACING_EXTINTn (DEBUG_BOOT_TRACING_PIN % _U_(0x10))
#define DEBUG_BOOT_TRACING_EXTINTb (_U_(0x1) << DEBUG_BOOT_TRACING_EXTINTn)
#define DEBUG_BOOT_TRACING_CONFIG_INDn (DEBUG_BOOT_TRACING_EXTINTn / _U_(0x8))
#define DEBUG_BOOT_TRACING_CONFIG_SENSEn (DEBUG_BOOT_TRACING_EXTINTn % _U_(0x8))
#define DEBUG_BOOT_TRACING_CONFIG_SENSEb (DEBUG_BOOT_TRACING_CONFIG_SENSEn * _U_(0x4))
#define DEBUG_BOOT_TRACING_IRQn (EIC_0_IRQn + DEBUG_BOOT_TRACING_EXTINTn)
// These macros are for compile time substitution
# define DEBUG_BOOT_TRACING_EXTINTn (DEBUG_BOOT_TRACING_PIN % _U_(0x10))
# define DEBUG_BOOT_TRACING_EXTINTb (_U_(0x1) << DEBUG_BOOT_TRACING_EXTINTn)
# define DEBUG_BOOT_TRACING_CONFIG_INDn (DEBUG_BOOT_TRACING_EXTINTn / _U_(0x8))
# define DEBUG_BOOT_TRACING_CONFIG_SENSEn (DEBUG_BOOT_TRACING_EXTINTn % _U_(0x8))
# define DEBUG_BOOT_TRACING_CONFIG_SENSEb (DEBUG_BOOT_TRACING_CONFIG_SENSEn * _U_(0x4))
# define DEBUG_BOOT_TRACING_IRQn (EIC_0_IRQn + DEBUG_BOOT_TRACING_EXTINTn)
//These macros perform PORT+PIN definition translation to IRQn in the preprocessor
#define PORTPIN_TO_IRQn_EXPAND(def) def
#define PORTPIN_TO_IRQn_DEF(def) PORTPIN_TO_IRQn_EXPAND(def)
#if DEBUG_BOOT_TRACING_PIN < 10
#define PORTPIN_TO_IRQn_TODEF(port, pin) PORTPIN_TO_IRQn_DEF(PIN_ ## port ## 0 ## pin ## A_EIC_EXTINT_NUM)
#else
#define PORTPIN_TO_IRQn_TODEF(port, pin) PORTPIN_TO_IRQn_DEF(PIN_ ## port ## pin ## A_EIC_EXTINT_NUM)
#endif
#define PORTPIN_TO_IRQn(port, pin) PORTPIN_TO_IRQn_TODEF(port, pin)
// These macros perform PORT+PIN definition translation to IRQn in the preprocessor
# define PORTPIN_TO_IRQn_EXPAND(def) def
# define PORTPIN_TO_IRQn_DEF(def) PORTPIN_TO_IRQn_EXPAND(def)
# if DEBUG_BOOT_TRACING_PIN < 10
# define PORTPIN_TO_IRQn_TODEF(port, pin) PORTPIN_TO_IRQn_DEF(PIN_##port##0##pin##A_EIC_EXTINT_NUM)
# else
# define PORTPIN_TO_IRQn_TODEF(port, pin) PORTPIN_TO_IRQn_DEF(PIN_##port##pin##A_EIC_EXTINT_NUM)
# endif
# define PORTPIN_TO_IRQn(port, pin) PORTPIN_TO_IRQn_TODEF(port, pin)
//These macros perform function name output in the preprocessor
#define DEBUG_BOOT_TRACING_HANDLER_CONCAT(irq) void EIC_ ## irq ## _Handler(void)
#define DEBUG_BOOT_TRACING_HANDLER(irq) DEBUG_BOOT_TRACING_HANDLER_CONCAT(irq)
// These macros perform function name output in the preprocessor
# define DEBUG_BOOT_TRACING_HANDLER_CONCAT(irq) void EIC_##irq##_Handler(void)
# define DEBUG_BOOT_TRACING_HANDLER(irq) DEBUG_BOOT_TRACING_HANDLER_CONCAT(irq)
//To generate the function name of the IRQ handler catching boot tracing,
// To generate the function name of the IRQ handler catching boot tracing,
// certain macros must be undefined, so save their current values to macro stack
#pragma push_macro("PA")
#pragma push_macro("PB")
#pragma push_macro("_L_")
# pragma push_macro("PA")
# pragma push_macro("PB")
# pragma push_macro("_L_")
//Undefine / redefine pushed macros
#undef PA
#undef PB
#undef _L_
#define _L_(x) x
// Undefine / redefine pushed macros
# undef PA
# undef PB
# undef _L_
# define _L_(x) x
//Perform the work and output
//Ex: PORT PB, PIN 31 = void EIC_15_Handler(void)
// Perform the work and output
// Ex: PORT PB, PIN 31 = void EIC_15_Handler(void)
DEBUG_BOOT_TRACING_HANDLER(PORTPIN_TO_IRQn(DEBUG_BOOT_TRACING_PORT, DEBUG_BOOT_TRACING_PIN))
//Restore macros
#pragma pop_macro("PA")
#pragma pop_macro("PB")
#pragma pop_macro("_L_")
// Restore macros
# pragma pop_macro("PA")
# pragma pop_macro("PB")
# pragma pop_macro("_L_")
{
//This is only for non-functional keyboard troubleshooting and should be disabled after boot
//Intention is to lock up the keyboard here with repeating debug led code
while (1)
{
// This is only for non-functional keyboard troubleshooting and should be disabled after boot
// Intention is to lock up the keyboard here with repeating debug led code
while (1) {
dled_print(debug_code, 1);
}
}
void debug_code_init(void)
{
void debug_code_init(void) {
DBGC(DC_UNSET);
//Configure Ports for EIC
PORT->Group[DEBUG_BOOT_TRACING_PORT].DIRCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; //Input
PORT->Group[DEBUG_BOOT_TRACING_PORT].OUTSET.reg = 1 << DEBUG_BOOT_TRACING_PIN; //High
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.INEN = 1; //Input Enable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PULLEN = 1; //Pull Enable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PMUXEN = 1; //Mux Enable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PMUX[DEBUG_BOOT_TRACING_PIN / 2].bit.PMUXO = 0; //Mux A
// Configure Ports for EIC
PORT->Group[DEBUG_BOOT_TRACING_PORT].DIRCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; // Input
PORT->Group[DEBUG_BOOT_TRACING_PORT].OUTSET.reg = 1 << DEBUG_BOOT_TRACING_PIN; // High
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.INEN = 1; // Input Enable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PULLEN = 1; // Pull Enable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PMUXEN = 1; // Mux Enable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PMUX[DEBUG_BOOT_TRACING_PIN / 2].bit.PMUXO = 0; // Mux A
//Enable CLK_EIC_APB
// Enable CLK_EIC_APB
MCLK->APBAMASK.bit.EIC_ = 1;
//Configure EIC
// Configure EIC
EIC->CTRLA.bit.SWRST = 1;
while (EIC->SYNCBUSY.bit.SWRST) {}
EIC->ASYNCH.reg = DEBUG_BOOT_TRACING_EXTINTb;
while (EIC->SYNCBUSY.bit.SWRST) {
}
EIC->ASYNCH.reg = DEBUG_BOOT_TRACING_EXTINTb;
EIC->INTENSET.reg = DEBUG_BOOT_TRACING_EXTINTb;
EIC->CONFIG[DEBUG_BOOT_TRACING_CONFIG_INDn].reg |= (EIC_CONFIG_SENSE0_FALL_Val << DEBUG_BOOT_TRACING_CONFIG_SENSEb);
EIC->CTRLA.bit.ENABLE = 1;
while (EIC->SYNCBUSY.bit.ENABLE) {}
while (EIC->SYNCBUSY.bit.ENABLE) {
}
//Enable EIC IRQ
// Enable EIC IRQ
NVIC_EnableIRQ(DEBUG_BOOT_TRACING_IRQn);
}
void debug_code_disable(void)
{
//Disable EIC IRQ
void debug_code_disable(void) {
// Disable EIC IRQ
NVIC_DisableIRQ(DEBUG_BOOT_TRACING_IRQn);
//Disable EIC
// Disable EIC
EIC->CTRLA.bit.ENABLE = 0;
while (EIC->SYNCBUSY.bit.ENABLE) {}
while (EIC->SYNCBUSY.bit.ENABLE) {
}
//Default port configuration
PORT->Group[DEBUG_BOOT_TRACING_PORT].DIRCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; //Input
PORT->Group[DEBUG_BOOT_TRACING_PORT].OUTCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; //Low
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.INEN = 0; //Input Disable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PULLEN = 0; //Pull Disable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PMUXEN = 0; //Mux Disable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PMUX[DEBUG_BOOT_TRACING_PIN / 2].bit.PMUXO = 0; //Mux A
// Default port configuration
PORT->Group[DEBUG_BOOT_TRACING_PORT].DIRCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; // Input
PORT->Group[DEBUG_BOOT_TRACING_PORT].OUTCLR.reg = 1 << DEBUG_BOOT_TRACING_PIN; // Low
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.INEN = 0; // Input Disable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PULLEN = 0; // Pull Disable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PINCFG[DEBUG_BOOT_TRACING_PIN].bit.PMUXEN = 0; // Mux Disable
PORT->Group[DEBUG_BOOT_TRACING_PORT].PMUX[DEBUG_BOOT_TRACING_PIN / 2].bit.PMUXO = 0; // Mux A
//Disable CLK_EIC_APB
// Disable CLK_EIC_APB
MCLK->APBAMASK.bit.EIC_ = 0;
}
@ -224,4 +239,4 @@ void debug_code_disable(void)
void debug_code_init(void) {}
void debug_code_disable(void) {}
#endif //DEBUG_BOOT_TRACING_ENABLE
#endif // DEBUG_BOOT_TRACING_ENABLE

View file

@ -22,54 +22,54 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Debug LED */
#if DEBUG_LED_ENABLE == 1
#define DBG_LED_ENA PORT->Group[DEBUG_LED_PORT].DIRSET.reg = (1 << DEBUG_LED_PIN)
#define DBG_LED_DIS PORT->Group[DEBUG_LED_PORT].DIRCLR.reg = (1 << DEBUG_LED_PIN)
#define DBG_LED_ON PORT->Group[DEBUG_LED_PORT].OUTSET.reg = (1 << DEBUG_LED_PIN)
#define DBG_LED_OFF PORT->Group[DEBUG_LED_PORT].OUTCLR.reg = (1 << DEBUG_LED_PIN)
# define DBG_LED_ENA PORT->Group[DEBUG_LED_PORT].DIRSET.reg = (1 << DEBUG_LED_PIN)
# define DBG_LED_DIS PORT->Group[DEBUG_LED_PORT].DIRCLR.reg = (1 << DEBUG_LED_PIN)
# define DBG_LED_ON PORT->Group[DEBUG_LED_PORT].OUTSET.reg = (1 << DEBUG_LED_PIN)
# define DBG_LED_OFF PORT->Group[DEBUG_LED_PORT].OUTCLR.reg = (1 << DEBUG_LED_PIN)
#else
#define DBG_LED_ENA
#define DBG_LED_DIS
#define DBG_LED_ON
#define DBG_LED_OFF
# define DBG_LED_ENA
# define DBG_LED_DIS
# define DBG_LED_ON
# define DBG_LED_OFF
#endif
/* Debug Port 1 */
#if DEBUG_PORT1_ENABLE == 1
#define DBG_1_ENA PORT->Group[DEBUG_PORT1_PORT].DIRSET.reg = (1 << DEBUG_PORT1_PIN)
#define DBG_1_DIS PORT->Group[DEBUG_PORT1_PORT].DIRCLR.reg = (1 << DEBUG_PORT1_PIN)
#define DBG_1_ON PORT->Group[DEBUG_PORT1_PORT].OUTSET.reg = (1 << DEBUG_PORT1_PIN)
#define DBG_1_OFF PORT->Group[DEBUG_PORT1_PORT].OUTCLR.reg = (1 << DEBUG_PORT1_PIN)
# define DBG_1_ENA PORT->Group[DEBUG_PORT1_PORT].DIRSET.reg = (1 << DEBUG_PORT1_PIN)
# define DBG_1_DIS PORT->Group[DEBUG_PORT1_PORT].DIRCLR.reg = (1 << DEBUG_PORT1_PIN)
# define DBG_1_ON PORT->Group[DEBUG_PORT1_PORT].OUTSET.reg = (1 << DEBUG_PORT1_PIN)
# define DBG_1_OFF PORT->Group[DEBUG_PORT1_PORT].OUTCLR.reg = (1 << DEBUG_PORT1_PIN)
#else
#define DBG_1_ENA
#define DBG_1_DIS
#define DBG_1_ON
#define DBG_1_OFF
# define DBG_1_ENA
# define DBG_1_DIS
# define DBG_1_ON
# define DBG_1_OFF
#endif
/* Debug Port 2 */
#if DEBUG_PORT2_ENABLE == 1
#define DBG_2_ENA PORT->Group[DEBUG_PORT2_PORT].DIRSET.reg = (1 << DEBUG_PORT2_PIN)
#define DBG_2_DIS PORT->Group[DEBUG_PORT2_PORT].DIRCLR.reg = (1 << DEBUG_PORT2_PIN)
#define DBG_2_ON PORT->Group[DEBUG_PORT2_PORT].OUTSET.reg = (1 << DEBUG_PORT2_PIN)
#define DBG_2_OFF PORT->Group[DEBUG_PORT2_PORT].OUTCLR.reg = (1 << DEBUG_PORT2_PIN)
# define DBG_2_ENA PORT->Group[DEBUG_PORT2_PORT].DIRSET.reg = (1 << DEBUG_PORT2_PIN)
# define DBG_2_DIS PORT->Group[DEBUG_PORT2_PORT].DIRCLR.reg = (1 << DEBUG_PORT2_PIN)
# define DBG_2_ON PORT->Group[DEBUG_PORT2_PORT].OUTSET.reg = (1 << DEBUG_PORT2_PIN)
# define DBG_2_OFF PORT->Group[DEBUG_PORT2_PORT].OUTCLR.reg = (1 << DEBUG_PORT2_PIN)
#else
#define DBG_2_ENA
#define DBG_2_DIS
#define DBG_2_ON
#define DBG_2_OFF
# define DBG_2_ENA
# define DBG_2_DIS
# define DBG_2_ON
# define DBG_2_OFF
#endif
/* Debug Port 3 */
#if DEBUG_PORT3_ENABLE == 1
#define DBG_3_ENA PORT->Group[DEBUG_PORT3_PORT].DIRSET.reg = (1 << DEBUG_PORT3_PIN)
#define DBG_3_DIS PORT->Group[DEBUG_PORT3_PORT].DIRCLR.reg = (1 << DEBUG_PORT3_PIN)
#define DBG_3_ON PORT->Group[DEBUG_PORT3_PORT].OUTSET.reg = (1 << DEBUG_PORT3_PIN)
#define DBG_3_OFF PORT->Group[DEBUG_PORT3_PORT].OUTCLR.reg = (1 << DEBUG_PORT3_PIN)
# define DBG_3_ENA PORT->Group[DEBUG_PORT3_PORT].DIRSET.reg = (1 << DEBUG_PORT3_PIN)
# define DBG_3_DIS PORT->Group[DEBUG_PORT3_PORT].DIRCLR.reg = (1 << DEBUG_PORT3_PIN)
# define DBG_3_ON PORT->Group[DEBUG_PORT3_PORT].OUTSET.reg = (1 << DEBUG_PORT3_PIN)
# define DBG_3_OFF PORT->Group[DEBUG_PORT3_PORT].OUTCLR.reg = (1 << DEBUG_PORT3_PIN)
#else
#define DBG_3_ENA
#define DBG_3_DIS
#define DBG_3_ON
#define DBG_3_OFF
# define DBG_3_ENA
# define DBG_3_DIS
# define DBG_3_ON
# define DBG_3_OFF
#endif
void dbg_print(uint32_t x);
@ -80,7 +80,7 @@ void debug_code_disable(void);
#ifdef DEBUG_BOOT_TRACING_ENABLE
#define DBGC(n) debug_code = n
# define DBGC(n) debug_code = n
extern volatile uint32_t debug_code;
@ -216,8 +216,9 @@ enum debug_code_list {
#else
#define DBGC(n) {}
# define DBGC(n) \
{}
#endif //DEBUG_BOOT_TRACING_ENABLE
#endif // DEBUG_BOOT_TRACING_ENABLE
#endif //_D51_UTIL_H_
#endif //_D51_UTIL_H_

View file

@ -19,77 +19,84 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
#include <string.h>
# include <string.h>
//From keyboard
#include "config.h"
#include "config_led.h"
#include "matrix.h"
// From keyboard
# include "config.h"
# include "config_led.h"
# include "matrix.h"
#define I2C_LED_USE_DMA 1 //Set 1 to use background DMA transfers for leds, Set 0 to use inline software transfers
# define I2C_LED_USE_DMA 1 // Set 1 to use background DMA transfers for leds, Set 0 to use inline software transfers
static uint8_t i2c_led_q[I2C_Q_SIZE]; //I2C queue circular buffer
static uint8_t i2c_led_q_s; //Start of circular buffer
static uint8_t i2c_led_q_e; //End of circular buffer
static uint8_t i2c_led_q_full; //Queue full counter for reset
static uint8_t i2c_led_q[I2C_Q_SIZE]; // I2C queue circular buffer
static uint8_t i2c_led_q_s; // Start of circular buffer
static uint8_t i2c_led_q_e; // End of circular buffer
static uint8_t i2c_led_q_full; // Queue full counter for reset
static uint8_t dma_sendbuf[I2C_DMA_MAX_SEND]; //Data being written to I2C
static uint8_t dma_sendbuf[I2C_DMA_MAX_SEND]; // Data being written to I2C
volatile uint8_t i2c_led_q_running;
#endif // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
#endif // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
void i2c0_init(void)
{
void i2c0_init(void) {
DBGC(DC_I2C0_INIT_BEGIN);
CLK_set_i2c0_freq(CHAN_SERCOM_I2C0, FREQ_I2C0_DEFAULT);
//MCU
PORT->Group[0].PMUX[4].bit.PMUXE = 2;
PORT->Group[0].PMUX[4].bit.PMUXO = 2;
// MCU
PORT->Group[0].PMUX[4].bit.PMUXE = 2;
PORT->Group[0].PMUX[4].bit.PMUXO = 2;
PORT->Group[0].PINCFG[8].bit.PMUXEN = 1;
PORT->Group[0].PINCFG[9].bit.PMUXEN = 1;
//I2C
//Note: SW Reset handled in CLK_set_i2c0_freq clks.c
// I2C
// Note: SW Reset handled in CLK_set_i2c0_freq clks.c
SERCOM0->I2CM.CTRLA.bit.MODE = 5; //Set master mode
SERCOM0->I2CM.CTRLA.bit.MODE = 5; // Set master mode
SERCOM0->I2CM.CTRLA.bit.SPEED = 0; //Set to 1 for Fast-mode Plus (FM+) up to 1 MHz
SERCOM0->I2CM.CTRLA.bit.RUNSTDBY = 1; //Enabled
SERCOM0->I2CM.CTRLA.bit.SPEED = 0; // Set to 1 for Fast-mode Plus (FM+) up to 1 MHz
SERCOM0->I2CM.CTRLA.bit.RUNSTDBY = 1; // Enabled
SERCOM0->I2CM.CTRLA.bit.ENABLE = 1; //Enable the device
while (SERCOM0->I2CM.SYNCBUSY.bit.ENABLE) { DBGC(DC_I2C0_INIT_SYNC_ENABLING); } //Wait for SYNCBUSY.ENABLE to clear
SERCOM0->I2CM.CTRLA.bit.ENABLE = 1; // Enable the device
while (SERCOM0->I2CM.SYNCBUSY.bit.ENABLE) {
DBGC(DC_I2C0_INIT_SYNC_ENABLING);
} // Wait for SYNCBUSY.ENABLE to clear
SERCOM0->I2CM.STATUS.bit.BUSSTATE = 1; //Force into IDLE state
while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) { DBGC(DC_I2C0_INIT_SYNC_SYSOP); }
while (SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1) { DBGC(DC_I2C0_INIT_WAIT_IDLE); } //Wait while not idle
SERCOM0->I2CM.STATUS.bit.BUSSTATE = 1; // Force into IDLE state
while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) {
DBGC(DC_I2C0_INIT_SYNC_SYSOP);
}
while (SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1) {
DBGC(DC_I2C0_INIT_WAIT_IDLE);
} // Wait while not idle
DBGC(DC_I2C0_INIT_COMPLETE);
}
uint8_t i2c0_start(uint8_t address)
{
uint8_t i2c0_start(uint8_t address) {
SERCOM0->I2CM.ADDR.bit.ADDR = address;
while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) {}
while (SERCOM0->I2CM.INTFLAG.bit.MB == 0) {}
while (SERCOM0->I2CM.STATUS.bit.RXNACK) {}
while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) {
}
while (SERCOM0->I2CM.INTFLAG.bit.MB == 0) {
}
while (SERCOM0->I2CM.STATUS.bit.RXNACK) {
}
return 1;
}
uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout)
{
uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout) {
if (!length) return 0;
i2c0_start(address);
while (length)
{
while (length) {
SERCOM0->I2CM.DATA.bit.DATA = *data;
while (SERCOM0->I2CM.INTFLAG.bit.MB == 0) {}
while (SERCOM0->I2CM.STATUS.bit.RXNACK) {}
while (SERCOM0->I2CM.INTFLAG.bit.MB == 0) {
}
while (SERCOM0->I2CM.STATUS.bit.RXNACK) {
}
data++;
length--;
@ -100,74 +107,83 @@ uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t
return 1;
}
void i2c0_stop(void)
{
if (SERCOM0->I2CM.STATUS.bit.CLKHOLD || SERCOM0->I2CM.INTFLAG.bit.MB == 1 || SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1)
{
void i2c0_stop(void) {
if (SERCOM0->I2CM.STATUS.bit.CLKHOLD || SERCOM0->I2CM.INTFLAG.bit.MB == 1 || SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1) {
SERCOM0->I2CM.CTRLB.bit.CMD = 3;
while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP);
while (SERCOM0->I2CM.STATUS.bit.CLKHOLD);
while (SERCOM0->I2CM.INTFLAG.bit.MB);
while (SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1);
while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP)
;
while (SERCOM0->I2CM.STATUS.bit.CLKHOLD)
;
while (SERCOM0->I2CM.INTFLAG.bit.MB)
;
while (SERCOM0->I2CM.STATUS.bit.BUSSTATE != 1)
;
}
}
#if !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
void i2c1_init(void)
{
void i2c1_init(void) {
DBGC(DC_I2C1_INIT_BEGIN);
CLK_set_i2c1_freq(CHAN_SERCOM_I2C1, FREQ_I2C1_DEFAULT);
/* MCU */
PORT->Group[0].PMUX[8].bit.PMUXE = 2;
PORT->Group[0].PMUX[8].bit.PMUXO = 2;
PORT->Group[0].PMUX[8].bit.PMUXE = 2;
PORT->Group[0].PMUX[8].bit.PMUXO = 2;
PORT->Group[0].PINCFG[16].bit.PMUXEN = 1;
PORT->Group[0].PINCFG[17].bit.PMUXEN = 1;
/* I2C */
//Note: SW Reset handled in CLK_set_i2c1_freq clks.c
// Note: SW Reset handled in CLK_set_i2c1_freq clks.c
SERCOM1->I2CM.CTRLA.bit.MODE = 5; //MODE: Set master mode (No sync)
SERCOM1->I2CM.CTRLA.bit.SPEED = 1; //SPEED: Fm+ up to 1MHz (No sync)
SERCOM1->I2CM.CTRLA.bit.RUNSTDBY = 1; //RUNSTBY: Enabled (No sync)
SERCOM1->I2CM.CTRLA.bit.MODE = 5; // MODE: Set master mode (No sync)
SERCOM1->I2CM.CTRLA.bit.SPEED = 1; // SPEED: Fm+ up to 1MHz (No sync)
SERCOM1->I2CM.CTRLA.bit.RUNSTDBY = 1; // RUNSTBY: Enabled (No sync)
SERCOM1->I2CM.CTRLB.bit.SMEN = 1; //SMEN: Smart mode enabled (For DMA)(No sync)
SERCOM1->I2CM.CTRLB.bit.SMEN = 1; // SMEN: Smart mode enabled (For DMA)(No sync)
NVIC_EnableIRQ(SERCOM1_0_IRQn);
SERCOM1->I2CM.INTENSET.bit.ERROR = 1;
SERCOM1->I2CM.CTRLA.bit.ENABLE = 1; //ENABLE: Enable the device (sync SYNCBUSY.ENABLE)
while (SERCOM1->I2CM.SYNCBUSY.bit.ENABLE) { DBGC(DC_I2C1_INIT_SYNC_ENABLING); } //Wait for SYNCBUSY.ENABLE to clear
SERCOM1->I2CM.CTRLA.bit.ENABLE = 1; // ENABLE: Enable the device (sync SYNCBUSY.ENABLE)
while (SERCOM1->I2CM.SYNCBUSY.bit.ENABLE) {
DBGC(DC_I2C1_INIT_SYNC_ENABLING);
} // Wait for SYNCBUSY.ENABLE to clear
SERCOM1->I2CM.STATUS.bit.BUSSTATE = 1; //BUSSTATE: Force into IDLE state (sync SYNCBUSY.SYSOP)
while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP) { DBGC(DC_I2C1_INIT_SYNC_SYSOP); }
while (SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1) { DBGC(DC_I2C1_INIT_WAIT_IDLE); } //Wait while not idle
SERCOM1->I2CM.STATUS.bit.BUSSTATE = 1; // BUSSTATE: Force into IDLE state (sync SYNCBUSY.SYSOP)
while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP) {
DBGC(DC_I2C1_INIT_SYNC_SYSOP);
}
while (SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1) {
DBGC(DC_I2C1_INIT_WAIT_IDLE);
} // Wait while not idle
DBGC(DC_I2C1_INIT_COMPLETE);
}
uint8_t i2c1_start(uint8_t address)
{
uint8_t i2c1_start(uint8_t address) {
SERCOM1->I2CM.ADDR.bit.ADDR = address;
while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP) {}
while (SERCOM1->I2CM.INTFLAG.bit.MB == 0) {}
while (SERCOM1->I2CM.STATUS.bit.RXNACK) {}
while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP) {
}
while (SERCOM1->I2CM.INTFLAG.bit.MB == 0) {
}
while (SERCOM1->I2CM.STATUS.bit.RXNACK) {
}
return 1;
}
uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout)
{
uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout) {
if (!length) return 0;
i2c1_start(address);
while (length)
{
while (length) {
SERCOM1->I2CM.DATA.bit.DATA = *data;
while (SERCOM1->I2CM.INTFLAG.bit.MB == 0) {}
while (SERCOM1->I2CM.STATUS.bit.RXNACK) {}
while (SERCOM1->I2CM.INTFLAG.bit.MB == 0) {
}
while (SERCOM1->I2CM.STATUS.bit.RXNACK) {
}
data++;
length--;
@ -178,33 +194,32 @@ uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t
return 1;
}
void i2c1_stop(void)
{
if (SERCOM1->I2CM.STATUS.bit.CLKHOLD || SERCOM1->I2CM.INTFLAG.bit.MB == 1 || SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1)
{
void i2c1_stop(void) {
if (SERCOM1->I2CM.STATUS.bit.CLKHOLD || SERCOM1->I2CM.INTFLAG.bit.MB == 1 || SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1) {
SERCOM1->I2CM.CTRLB.bit.CMD = 3;
while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP);
while (SERCOM1->I2CM.STATUS.bit.CLKHOLD);
while (SERCOM1->I2CM.INTFLAG.bit.MB);
while (SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1);
while (SERCOM1->I2CM.SYNCBUSY.bit.SYSOP)
;
while (SERCOM1->I2CM.STATUS.bit.CLKHOLD)
;
while (SERCOM1->I2CM.INTFLAG.bit.MB)
;
while (SERCOM1->I2CM.STATUS.bit.BUSSTATE != 1)
;
}
}
void i2c_led_send_CRWL(uint8_t drvid)
{
uint8_t i2cdata[] = { ISSI3733_CMDRWL, ISSI3733_CMDRWL_WRITE_ENABLE_ONCE };
void i2c_led_send_CRWL(uint8_t drvid) {
uint8_t i2cdata[] = {ISSI3733_CMDRWL, ISSI3733_CMDRWL_WRITE_ENABLE_ONCE};
i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
}
void i2c_led_select_page(uint8_t drvid, uint8_t pageno)
{
uint8_t i2cdata[] = { ISSI3733_CMDR, pageno };
void i2c_led_select_page(uint8_t drvid, uint8_t pageno) {
uint8_t i2cdata[] = {ISSI3733_CMDR, pageno};
i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
}
void i2c_led_send_GCR(uint8_t drvid)
{
uint8_t i2cdata[] = { ISSI3733_GCCR, 0x00 };
void i2c_led_send_GCR(uint8_t drvid) {
uint8_t i2cdata[] = {ISSI3733_GCCR, 0x00};
if (gcr_actual > LED_GCR_MAX) gcr_actual = LED_GCR_MAX;
i2cdata[1] = gcr_actual;
@ -212,57 +227,50 @@ void i2c_led_send_GCR(uint8_t drvid)
i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
}
void i2c_led_send_onoff(uint8_t drvid)
{
#if I2C_LED_USE_DMA != 1
if (!i2c_led_q_running)
{
#endif
void i2c_led_send_onoff(uint8_t drvid) {
# if I2C_LED_USE_DMA != 1
if (!i2c_led_q_running) {
# endif
i2c_led_send_CRWL(drvid);
i2c_led_select_page(drvid, 0);
#if I2C_LED_USE_DMA != 1
# if I2C_LED_USE_DMA != 1
}
#endif
# endif
*issidrv[drvid].onoff = 0; //Force start location offset to zero
*issidrv[drvid].onoff = 0; // Force start location offset to zero
i2c1_transmit(issidrv[drvid].addr, issidrv[drvid].onoff, ISSI3733_PG0_BYTES, 0);
}
void i2c_led_send_mode_op_gcr(uint8_t drvid, uint8_t mode, uint8_t operation)
{
uint8_t i2cdata[] = { ISSI3733_CR, mode | operation, gcr_actual};
void i2c_led_send_mode_op_gcr(uint8_t drvid, uint8_t mode, uint8_t operation) {
uint8_t i2cdata[] = {ISSI3733_CR, mode | operation, gcr_actual};
i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
}
void i2c_led_send_pur_pdr(uint8_t drvid, uint8_t pur, uint8_t pdr)
{
uint8_t i2cdata[] = { ISSI3733_SWYR_PUR, pur, pdr };
void i2c_led_send_pur_pdr(uint8_t drvid, uint8_t pur, uint8_t pdr) {
uint8_t i2cdata[] = {ISSI3733_SWYR_PUR, pur, pdr};
i2c1_transmit(issidrv[drvid].addr, i2cdata, sizeof(i2cdata), 0);
}
void i2c_led_send_pwm(uint8_t drvid)
{
#if I2C_LED_USE_DMA != 1
if (!i2c_led_q_running)
{
#endif
void i2c_led_send_pwm(uint8_t drvid) {
# if I2C_LED_USE_DMA != 1
if (!i2c_led_q_running) {
# endif
i2c_led_send_CRWL(drvid);
i2c_led_select_page(drvid, 0);
#if I2C_LED_USE_DMA != 1
# if I2C_LED_USE_DMA != 1
}
#endif
# endif
*issidrv[drvid].pwm = 0; //Force start location offset to zero
*issidrv[drvid].pwm = 0; // Force start location offset to zero
i2c1_transmit(issidrv[drvid].addr, issidrv[drvid].pwm, ISSI3733_PG1_BYTES, 0);
}
uint8_t I2C3733_Init_Control(void)
{
uint8_t I2C3733_Init_Control(void) {
DBGC(DC_I2C3733_INIT_CONTROL_BEGIN);
//Hardware state shutdown on boot
//USB state machine will enable driver when communication is ready
// Hardware state shutdown on boot
// USB state machine will enable driver when communication is ready
I2C3733_Control_Set(0);
wait_ms(1);
@ -277,25 +285,24 @@ uint8_t I2C3733_Init_Control(void)
return 1;
}
uint8_t I2C3733_Init_Drivers(void)
{
uint8_t I2C3733_Init_Drivers(void) {
DBGC(DC_I2C3733_INIT_DRIVERS_BEGIN);
gcr_actual = ISSI3733_GCR_DEFAULT;
gcr_actual = ISSI3733_GCR_DEFAULT;
gcr_actual_last = gcr_actual;
if (gcr_actual > LED_GCR_MAX) gcr_actual = LED_GCR_MAX;
gcr_desired = gcr_actual;
//Set up master device
// Set up master device
i2c_led_send_CRWL(0);
i2c_led_select_page(0, 3);
i2c_led_send_mode_op_gcr(0, 0, ISSI3733_CR_SSD_NORMAL); //No SYNC due to brightness mismatch with second driver
i2c_led_send_mode_op_gcr(0, 0, ISSI3733_CR_SSD_NORMAL); // No SYNC due to brightness mismatch with second driver
//Set up slave device
// Set up slave device
i2c_led_send_CRWL(1);
i2c_led_select_page(1, 3);
i2c_led_send_mode_op_gcr(1, 0, ISSI3733_CR_SSD_NORMAL); //No SYNC due to brightness mismatch with first driver and slight flicker at rgb values 1,2
i2c_led_send_mode_op_gcr(1, 0, ISSI3733_CR_SSD_NORMAL); // No SYNC due to brightness mismatch with first driver and slight flicker at rgb values 1,2
i2c_led_send_CRWL(0);
i2c_led_select_page(0, 3);
@ -310,51 +317,54 @@ uint8_t I2C3733_Init_Drivers(void)
return 1;
}
void I2C_DMAC_LED_Init(void)
{
void I2C_DMAC_LED_Init(void) {
Dmac *dmac = DMAC;
DBGC(DC_I2C_DMAC_LED_INIT_BEGIN);
//Disable device
dmac->CTRL.bit.DMAENABLE = 0; //Disable DMAC
while (dmac->CTRL.bit.DMAENABLE) {} //Wait for disabled state in case of ongoing transfers
dmac->CTRL.bit.SWRST = 1; //Software Reset DMAC
while (dmac->CTRL.bit.SWRST) {} //Wait for software reset to complete
// Disable device
dmac->CTRL.bit.DMAENABLE = 0; // Disable DMAC
while (dmac->CTRL.bit.DMAENABLE) {
} // Wait for disabled state in case of ongoing transfers
dmac->CTRL.bit.SWRST = 1; // Software Reset DMAC
while (dmac->CTRL.bit.SWRST) {
} // Wait for software reset to complete
//Configure device
dmac->BASEADDR.reg = (uint32_t)&dmac_desc; //Set descriptor base address
dmac->WRBADDR.reg = (uint32_t)&dmac_desc_wb; //Set descriptor write back address
dmac->CTRL.reg |= 0x0f00; //Handle all priorities (LVL0-3)
// Configure device
dmac->BASEADDR.reg = (uint32_t)&dmac_desc; // Set descriptor base address
dmac->WRBADDR.reg = (uint32_t)&dmac_desc_wb; // Set descriptor write back address
dmac->CTRL.reg |= 0x0f00; // Handle all priorities (LVL0-3)
//Disable channel
dmac->Channel[0].CHCTRLA.bit.ENABLE = 0; //Disable the channel
while (dmac->Channel[0].CHCTRLA.bit.ENABLE) {} //Wait for disabled state in case of ongoing transfers
dmac->Channel[0].CHCTRLA.bit.SWRST = 1; //Software Reset the channel
while (dmac->Channel[0].CHCTRLA.bit.SWRST) {} //Wait for software reset to complete
// Disable channel
dmac->Channel[0].CHCTRLA.bit.ENABLE = 0; // Disable the channel
while (dmac->Channel[0].CHCTRLA.bit.ENABLE) {
} // Wait for disabled state in case of ongoing transfers
dmac->Channel[0].CHCTRLA.bit.SWRST = 1; // Software Reset the channel
while (dmac->Channel[0].CHCTRLA.bit.SWRST) {
} // Wait for software reset to complete
//Configure channel
dmac->Channel[0].CHCTRLA.bit.THRESHOLD = 0; //1BEAT
dmac->Channel[0].CHCTRLA.bit.BURSTLEN = 0; //SINGLE
dmac->Channel[0].CHCTRLA.bit.TRIGACT = 2; //BURST
dmac->Channel[0].CHCTRLA.bit.TRIGSRC = SERCOM1_DMAC_ID_TX; //Trigger source
dmac->Channel[0].CHCTRLA.bit.RUNSTDBY = 1; //Run in standby
// Configure channel
dmac->Channel[0].CHCTRLA.bit.THRESHOLD = 0; // 1BEAT
dmac->Channel[0].CHCTRLA.bit.BURSTLEN = 0; // SINGLE
dmac->Channel[0].CHCTRLA.bit.TRIGACT = 2; // BURST
dmac->Channel[0].CHCTRLA.bit.TRIGSRC = SERCOM1_DMAC_ID_TX; // Trigger source
dmac->Channel[0].CHCTRLA.bit.RUNSTDBY = 1; // Run in standby
NVIC_EnableIRQ(DMAC_0_IRQn);
dmac->Channel[0].CHINTENSET.bit.TCMPL = 1;
dmac->Channel[0].CHINTENSET.bit.TERR = 1;
dmac->Channel[0].CHINTENSET.bit.TERR = 1;
//Enable device
dmac->CTRL.bit.DMAENABLE = 1; //Enable DMAC
while (dmac->CTRL.bit.DMAENABLE == 0) {} //Wait for enable state
// Enable device
dmac->CTRL.bit.DMAENABLE = 1; // Enable DMAC
while (dmac->CTRL.bit.DMAENABLE == 0) {
} // Wait for enable state
DBGC(DC_I2C_DMAC_LED_INIT_COMPLETE);
}
//state = 1 enable
//state = 0 disable
void I2C3733_Control_Set(uint8_t state)
{
// state = 1 enable
// state = 0 disable
void I2C3733_Control_Set(uint8_t state) {
DBGC(DC_I2C3733_CONTROL_SET_BEGIN);
sr_exp_data.bit.SDB_N = (state == 1 ? 1 : 0);
@ -363,131 +373,111 @@ void I2C3733_Control_Set(uint8_t state)
DBGC(DC_I2C3733_CONTROL_SET_COMPLETE);
}
void i2c_led_desc_defaults(void)
{
dmac_desc.BTCTRL.bit.STEPSIZE = 0; //SRCINC used in favor for auto 1 inc
dmac_desc.BTCTRL.bit.STEPSEL = 0; //SRCINC used in favor for auto 1 inc
dmac_desc.BTCTRL.bit.DSTINC = 0; //The Destination Address Increment is disabled
dmac_desc.BTCTRL.bit.SRCINC = 1; //The Source Address Increment is enabled (Inc by 1)
dmac_desc.BTCTRL.bit.BEATSIZE = 0; //8-bit bus transfer
dmac_desc.BTCTRL.bit.BLOCKACT = 0; //Channel will be disabled if it is the last block transfer in the transaction
dmac_desc.BTCTRL.bit.EVOSEL = 0; //Event generation disabled
dmac_desc.BTCTRL.bit.VALID = 1; //Set dmac valid
void i2c_led_desc_defaults(void) {
dmac_desc.BTCTRL.bit.STEPSIZE = 0; // SRCINC used in favor for auto 1 inc
dmac_desc.BTCTRL.bit.STEPSEL = 0; // SRCINC used in favor for auto 1 inc
dmac_desc.BTCTRL.bit.DSTINC = 0; // The Destination Address Increment is disabled
dmac_desc.BTCTRL.bit.SRCINC = 1; // The Source Address Increment is enabled (Inc by 1)
dmac_desc.BTCTRL.bit.BEATSIZE = 0; // 8-bit bus transfer
dmac_desc.BTCTRL.bit.BLOCKACT = 0; // Channel will be disabled if it is the last block transfer in the transaction
dmac_desc.BTCTRL.bit.EVOSEL = 0; // Event generation disabled
dmac_desc.BTCTRL.bit.VALID = 1; // Set dmac valid
}
void i2c_led_prepare_send_dma(uint8_t *data, uint8_t len)
{
void i2c_led_prepare_send_dma(uint8_t *data, uint8_t len) {
i2c_led_desc_defaults();
dmac_desc.BTCNT.reg = len;
dmac_desc.SRCADDR.reg = (uint32_t)data + len;
dmac_desc.DSTADDR.reg = (uint32_t)&SERCOM1->I2CM.DATA.reg;
dmac_desc.BTCNT.reg = len;
dmac_desc.SRCADDR.reg = (uint32_t)data + len;
dmac_desc.DSTADDR.reg = (uint32_t)&SERCOM1->I2CM.DATA.reg;
dmac_desc.DESCADDR.reg = 0;
}
void i2c_led_begin_dma(uint8_t drvid)
{
DMAC->Channel[0].CHCTRLA.bit.ENABLE = 1; //Enable the channel
void i2c_led_begin_dma(uint8_t drvid) {
DMAC->Channel[0].CHCTRLA.bit.ENABLE = 1; // Enable the channel
SERCOM1->I2CM.ADDR.reg = (dmac_desc.BTCNT.reg << 16) | 0x2000 | issidrv[drvid].addr; //Begin transfer
SERCOM1->I2CM.ADDR.reg = (dmac_desc.BTCNT.reg << 16) | 0x2000 | issidrv[drvid].addr; // Begin transfer
}
void i2c_led_send_CRWL_dma(uint8_t drvid)
{
*(dma_sendbuf+0) = ISSI3733_CMDRWL;
*(dma_sendbuf+1) = ISSI3733_CMDRWL_WRITE_ENABLE_ONCE;
void i2c_led_send_CRWL_dma(uint8_t drvid) {
*(dma_sendbuf + 0) = ISSI3733_CMDRWL;
*(dma_sendbuf + 1) = ISSI3733_CMDRWL_WRITE_ENABLE_ONCE;
i2c_led_prepare_send_dma(dma_sendbuf, 2);
i2c_led_begin_dma(drvid);
}
void i2c_led_select_page_dma(uint8_t drvid, uint8_t pageno)
{
*(dma_sendbuf+0) = ISSI3733_CMDR;
*(dma_sendbuf+1) = pageno;
void i2c_led_select_page_dma(uint8_t drvid, uint8_t pageno) {
*(dma_sendbuf + 0) = ISSI3733_CMDR;
*(dma_sendbuf + 1) = pageno;
i2c_led_prepare_send_dma(dma_sendbuf, 2);
i2c_led_begin_dma(drvid);
}
void i2c_led_send_GCR_dma(uint8_t drvid)
{
*(dma_sendbuf+0) = ISSI3733_GCCR;
*(dma_sendbuf+1) = gcr_actual;
void i2c_led_send_GCR_dma(uint8_t drvid) {
*(dma_sendbuf + 0) = ISSI3733_GCCR;
*(dma_sendbuf + 1) = gcr_actual;
i2c_led_prepare_send_dma(dma_sendbuf, 2);
i2c_led_begin_dma(drvid);
}
void i2c_led_send_pwm_dma(uint8_t drvid)
{
//Note: This copies the CURRENT pwm buffer, which may be getting modified
void i2c_led_send_pwm_dma(uint8_t drvid) {
// Note: This copies the CURRENT pwm buffer, which may be getting modified
memcpy(dma_sendbuf, issidrv[drvid].pwm, ISSI3733_PG1_BYTES);
*dma_sendbuf = 0; //Force start location offset to zero
*dma_sendbuf = 0; // Force start location offset to zero
i2c_led_prepare_send_dma(dma_sendbuf, ISSI3733_PG1_BYTES);
i2c_led_begin_dma(drvid);
}
void i2c_led_send_onoff_dma(uint8_t drvid)
{
//Note: This copies the CURRENT onoff buffer, which may be getting modified
void i2c_led_send_onoff_dma(uint8_t drvid) {
// Note: This copies the CURRENT onoff buffer, which may be getting modified
memcpy(dma_sendbuf, issidrv[drvid].onoff, ISSI3733_PG0_BYTES);
*dma_sendbuf = 0; //Force start location offset to zero
*dma_sendbuf = 0; // Force start location offset to zero
i2c_led_prepare_send_dma(dma_sendbuf, ISSI3733_PG0_BYTES);
i2c_led_begin_dma(drvid);
}
void i2c_led_q_init(void)
{
void i2c_led_q_init(void) {
memset(i2c_led_q, 0, I2C_Q_SIZE);
i2c_led_q_s = 0;
i2c_led_q_e = 0;
i2c_led_q_s = 0;
i2c_led_q_e = 0;
i2c_led_q_running = 0;
i2c_led_q_full = 0;
i2c_led_q_full = 0;
}
uint8_t i2c_led_q_isempty(void)
{
return i2c_led_q_s == i2c_led_q_e;
uint8_t i2c_led_q_isempty(void) { return i2c_led_q_s == i2c_led_q_e; }
uint8_t i2c_led_q_size(void) { return (i2c_led_q_e - i2c_led_q_s) % I2C_Q_SIZE; }
uint8_t i2c_led_q_available(void) {
return I2C_Q_SIZE - i2c_led_q_size() - 1; // Never allow end to meet start
}
uint8_t i2c_led_q_size(void)
{
return (i2c_led_q_e - i2c_led_q_s) % I2C_Q_SIZE;
}
void i2c_led_q_add(uint8_t cmd) {
// WARNING: Always request room before adding commands!
uint8_t i2c_led_q_available(void)
{
return I2C_Q_SIZE - i2c_led_q_size() - 1; //Never allow end to meet start
}
void i2c_led_q_add(uint8_t cmd)
{
//WARNING: Always request room before adding commands!
//Assign command
// Assign command
i2c_led_q[i2c_led_q_e] = cmd;
i2c_led_q_e = (i2c_led_q_e + 1) % I2C_Q_SIZE; //Move end up one or wrap
i2c_led_q_e = (i2c_led_q_e + 1) % I2C_Q_SIZE; // Move end up one or wrap
}
void i2c_led_q_s_advance(void)
{
i2c_led_q_s = (i2c_led_q_s + 1) % I2C_Q_SIZE; //Move start up one or wrap
void i2c_led_q_s_advance(void) {
i2c_led_q_s = (i2c_led_q_s + 1) % I2C_Q_SIZE; // Move start up one or wrap
}
//Always request room before adding commands
//PS: In case the queue somehow gets filled, it will reset if it can not clear up
//PS: Could only get this to happen through unrealistic timings to overload the I2C bus
uint8_t i2c_led_q_request_room(uint8_t request_size)
{
if (request_size > i2c_led_q_available())
{
// Always request room before adding commands
// PS: In case the queue somehow gets filled, it will reset if it can not clear up
// PS: Could only get this to happen through unrealistic timings to overload the I2C bus
uint8_t i2c_led_q_request_room(uint8_t request_size) {
if (request_size > i2c_led_q_available()) {
i2c_led_q_full++;
if (i2c_led_q_full >= 100) //Give the queue a chance to clear up
if (i2c_led_q_full >= 100) // Give the queue a chance to clear up
{
DBG_LED_ON;
I2C_DMAC_LED_Init();
@ -503,10 +493,8 @@ uint8_t i2c_led_q_request_room(uint8_t request_size)
return 1;
}
uint8_t i2c_led_q_run(void)
{
if (i2c_led_q_isempty())
{
uint8_t i2c_led_q_run(void) {
if (i2c_led_q_isempty()) {
i2c_led_q_running = 0;
return 0;
}
@ -515,72 +503,62 @@ uint8_t i2c_led_q_run(void)
i2c_led_q_running = 1;
#if I2C_LED_USE_DMA != 1
while (!i2c_led_q_isempty())
{
#endif
//run command
if (i2c_led_q[i2c_led_q_s] == I2C_Q_CRWL)
{
# if I2C_LED_USE_DMA != 1
while (!i2c_led_q_isempty()) {
# endif
// run command
if (i2c_led_q[i2c_led_q_s] == I2C_Q_CRWL) {
i2c_led_q_s_advance();
uint8_t drvid = i2c_led_q[i2c_led_q_s];
#if I2C_LED_USE_DMA == 1
# if I2C_LED_USE_DMA == 1
i2c_led_send_CRWL_dma(drvid);
#else
i2c_led_send_CRWL(drvid);
#endif
}
else if (i2c_led_q[i2c_led_q_s] == I2C_Q_PAGE_SELECT)
{
# else
i2c_led_send_CRWL(drvid);
# endif
} else if (i2c_led_q[i2c_led_q_s] == I2C_Q_PAGE_SELECT) {
i2c_led_q_s_advance();
uint8_t drvid = i2c_led_q[i2c_led_q_s];
i2c_led_q_s_advance();
uint8_t page = i2c_led_q[i2c_led_q_s];
#if I2C_LED_USE_DMA == 1
# if I2C_LED_USE_DMA == 1
i2c_led_select_page_dma(drvid, page);
#else
i2c_led_select_page(drvid, page);
#endif
}
else if (i2c_led_q[i2c_led_q_s] == I2C_Q_PWM)
{
# else
i2c_led_select_page(drvid, page);
# endif
} else if (i2c_led_q[i2c_led_q_s] == I2C_Q_PWM) {
i2c_led_q_s_advance();
uint8_t drvid = i2c_led_q[i2c_led_q_s];
#if I2C_LED_USE_DMA == 1
# if I2C_LED_USE_DMA == 1
i2c_led_send_pwm_dma(drvid);
#else
i2c_led_send_pwm(drvid);
#endif
}
else if (i2c_led_q[i2c_led_q_s] == I2C_Q_GCR)
{
# else
i2c_led_send_pwm(drvid);
# endif
} else if (i2c_led_q[i2c_led_q_s] == I2C_Q_GCR) {
i2c_led_q_s_advance();
uint8_t drvid = i2c_led_q[i2c_led_q_s];
#if I2C_LED_USE_DMA == 1
# if I2C_LED_USE_DMA == 1
i2c_led_send_GCR_dma(drvid);
#else
i2c_led_send_GCR(drvid);
#endif
}
else if (i2c_led_q[i2c_led_q_s] == I2C_Q_ONOFF)
{
# else
i2c_led_send_GCR(drvid);
# endif
} else if (i2c_led_q[i2c_led_q_s] == I2C_Q_ONOFF) {
i2c_led_q_s_advance();
uint8_t drvid = i2c_led_q[i2c_led_q_s];
#if I2C_LED_USE_DMA == 1
# if I2C_LED_USE_DMA == 1
i2c_led_send_onoff_dma(drvid);
#else
i2c_led_send_onoff(drvid);
#endif
# else
i2c_led_send_onoff(drvid);
# endif
}
i2c_led_q_s_advance(); //Advance last run command or if the command byte was not serviced
i2c_led_q_s_advance(); // Advance last run command or if the command byte was not serviced
#if I2C_LED_USE_DMA != 1
# if I2C_LED_USE_DMA != 1
}
i2c_led_q_running = 0;
#endif
# endif
return 1;
}
#endif // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)
#endif // !defined(MD_BOOTLOADER) && defined(RGB_MATRIX_ENABLE)

View file

@ -20,89 +20,85 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef MD_BOOTLOADER
#include "samd51j18a.h"
#include "issi3733_driver.h"
#include "config.h"
# include "samd51j18a.h"
# include "issi3733_driver.h"
# include "config.h"
__attribute__((__aligned__(16)))
DmacDescriptor dmac_desc;
__attribute__((__aligned__(16)))
DmacDescriptor dmac_desc_wb;
__attribute__((__aligned__(16))) DmacDescriptor dmac_desc;
__attribute__((__aligned__(16))) DmacDescriptor dmac_desc_wb;
uint8_t I2C3733_Init_Control(void);
uint8_t I2C3733_Init_Drivers(void);
void I2C3733_Control_Set(uint8_t state);
void I2C_DMAC_LED_Init(void);
void I2C3733_Control_Set(uint8_t state);
void I2C_DMAC_LED_Init(void);
#define I2C_Q_SIZE 100
# define I2C_Q_SIZE 100
#define I2C_Q_NA 100
#define I2C_Q_CRWL 101
#define I2C_Q_PAGE_SELECT 102
#define I2C_Q_PWM 103
#define I2C_Q_GCR 104
#define I2C_Q_ONOFF 105
# define I2C_Q_NA 100
# define I2C_Q_CRWL 101
# define I2C_Q_PAGE_SELECT 102
# define I2C_Q_PWM 103
# define I2C_Q_GCR 104
# define I2C_Q_ONOFF 105
#define I2C_DMA_MAX_SEND 255
# define I2C_DMA_MAX_SEND 255
extern volatile uint8_t i2c_led_q_running;
#define I2C_LED_Q_PWM(a) { \
if (i2c_led_q_request_room(7)) \
{ \
i2c_led_q_add(I2C_Q_CRWL); \
i2c_led_q_add(a); \
i2c_led_q_add(I2C_Q_PAGE_SELECT); \
i2c_led_q_add(a); \
i2c_led_q_add(ISSI3733_PG_PWM); \
i2c_led_q_add(I2C_Q_PWM); \
i2c_led_q_add(a); \
} \
}
# define I2C_LED_Q_PWM(a) \
{ \
if (i2c_led_q_request_room(7)) { \
i2c_led_q_add(I2C_Q_CRWL); \
i2c_led_q_add(a); \
i2c_led_q_add(I2C_Q_PAGE_SELECT); \
i2c_led_q_add(a); \
i2c_led_q_add(ISSI3733_PG_PWM); \
i2c_led_q_add(I2C_Q_PWM); \
i2c_led_q_add(a); \
} \
}
#define I2C_LED_Q_GCR(a) { \
if (i2c_led_q_request_room(7)) \
{ \
i2c_led_q_add(I2C_Q_CRWL); \
i2c_led_q_add(a); \
i2c_led_q_add(I2C_Q_PAGE_SELECT); \
i2c_led_q_add(a); \
i2c_led_q_add(ISSI3733_PG_FN); \
i2c_led_q_add(I2C_Q_GCR); \
i2c_led_q_add(a); \
} \
}
# define I2C_LED_Q_GCR(a) \
{ \
if (i2c_led_q_request_room(7)) { \
i2c_led_q_add(I2C_Q_CRWL); \
i2c_led_q_add(a); \
i2c_led_q_add(I2C_Q_PAGE_SELECT); \
i2c_led_q_add(a); \
i2c_led_q_add(ISSI3733_PG_FN); \
i2c_led_q_add(I2C_Q_GCR); \
i2c_led_q_add(a); \
} \
}
#define I2C_LED_Q_ONOFF(a) { \
if (i2c_led_q_request_room(7)) \
{ \
i2c_led_q_add(I2C_Q_CRWL); \
i2c_led_q_add(a); \
i2c_led_q_add(I2C_Q_PAGE_SELECT); \
i2c_led_q_add(a); \
i2c_led_q_add(ISSI3733_PG_ONOFF); \
i2c_led_q_add(I2C_Q_ONOFF); \
i2c_led_q_add(a); \
} \
}
# define I2C_LED_Q_ONOFF(a) \
{ \
if (i2c_led_q_request_room(7)) { \
i2c_led_q_add(I2C_Q_CRWL); \
i2c_led_q_add(a); \
i2c_led_q_add(I2C_Q_PAGE_SELECT); \
i2c_led_q_add(a); \
i2c_led_q_add(ISSI3733_PG_ONOFF); \
i2c_led_q_add(I2C_Q_ONOFF); \
i2c_led_q_add(a); \
} \
}
void i2c_led_q_init(void);
void i2c_led_q_add(uint8_t cmd);
void i2c_led_q_s_advance(void);
void i2c_led_q_init(void);
void i2c_led_q_add(uint8_t cmd);
void i2c_led_q_s_advance(void);
uint8_t i2c_led_q_size(void);
uint8_t i2c_led_q_request_room(uint8_t request_size);
uint8_t i2c_led_q_run(void);
void i2c1_init(void);
void i2c1_init(void);
uint8_t i2c1_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout);
void i2c1_stop(void);
void i2c1_stop(void);
#endif //MD_BOOTLOADER
#endif // MD_BOOTLOADER
void i2c0_init(void);
void i2c0_init(void);
uint8_t i2c0_transmit(uint8_t address, uint8_t *data, uint16_t length, uint16_t timeout);
void i2c0_stop(void);
#endif // _I2C_MASTER_H_
void i2c0_stop(void);
#endif // _I2C_MASTER_H_

View file

@ -18,31 +18,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _ISSI3733_DRIVER_H_
#define _ISSI3733_DRIVER_H_
//ISII3733 Registers
// ISII3733 Registers
#define ISSI3733_CMDR 0xFD //Command Register (Write Only)
#define ISSI3733_CMDR 0xFD // Command Register (Write Only)
#define ISSI3733_CMDRWL 0xFE //Command Register Write Lock (Read/Write)
#define ISSI3733_CMDRWL_WRITE_DISABLE 0x00 //Lock register
#define ISSI3733_CMDRWL_WRITE_ENABLE_ONCE 0xC5 //Enable one write to register then reset to locked
#define ISSI3733_CMDRWL 0xFE // Command Register Write Lock (Read/Write)
#define ISSI3733_CMDRWL_WRITE_DISABLE 0x00 // Lock register
#define ISSI3733_CMDRWL_WRITE_ENABLE_ONCE 0xC5 // Enable one write to register then reset to locked
#define ISSI3733_IMR 0xF0 //Interrupt Mask Register (Write Only)
#define ISSI3733_IMR_IAC_ON 0x08 //Auto Clear Interrupt Bit - Interrupt auto clear when INTB stay low exceeds 8ms
#define ISSI3733_IMR_IAB_ON 0x04 //Auto Breath Interrupt Bit - Enable auto breath loop finish interrupt
#define ISSI3733_IMR_IS_ON 0x02 //Dot Short Interrupt Bit - Enable dot short interrupt
#define ISSI3733_IMR_IO_ON 0x01 //Dot Open Interrupt Bit - Enable dot open interrupt
#define ISSI3733_IMR 0xF0 // Interrupt Mask Register (Write Only)
#define ISSI3733_IMR_IAC_ON 0x08 // Auto Clear Interrupt Bit - Interrupt auto clear when INTB stay low exceeds 8ms
#define ISSI3733_IMR_IAB_ON 0x04 // Auto Breath Interrupt Bit - Enable auto breath loop finish interrupt
#define ISSI3733_IMR_IS_ON 0x02 // Dot Short Interrupt Bit - Enable dot short interrupt
#define ISSI3733_IMR_IO_ON 0x01 // Dot Open Interrupt Bit - Enable dot open interrupt
#define ISSI3733_ISR 0xF1 //Interrupt Status Register (Read Only)
#define ISSI3733_ISR_ABM3_FINISH 0x10 //Auto Breath Mode 3 Finish Bit - ABM3 finished
#define ISSI3733_ISR_ABM2_FINISH 0x08 //Auto Breath Mode 2 Finish Bit - ABM2 finished
#define ISSI3733_ISR_ABM1_FINISH 0x04 //Auto Breath Mode 1 Finish Bit - ABM1 finished
#define ISSI3733_ISR_SB 0x02 //Short Bit - Shorted
#define ISSI3733_ISR_OB 0x01 //Open Bit - Opened
#define ISSI3733_ISR 0xF1 // Interrupt Status Register (Read Only)
#define ISSI3733_ISR_ABM3_FINISH 0x10 // Auto Breath Mode 3 Finish Bit - ABM3 finished
#define ISSI3733_ISR_ABM2_FINISH 0x08 // Auto Breath Mode 2 Finish Bit - ABM2 finished
#define ISSI3733_ISR_ABM1_FINISH 0x04 // Auto Breath Mode 1 Finish Bit - ABM1 finished
#define ISSI3733_ISR_SB 0x02 // Short Bit - Shorted
#define ISSI3733_ISR_OB 0x01 // Open Bit - Opened
#define ISSI3733_PG0 0x00 //LED Control Register
#define ISSI3733_PG1 0x01 //PWM Register
#define ISSI3733_PG2 0x02 //Auto Breath Mode Register
#define ISSI3733_PG3 0x03 //Function Register
#define ISSI3733_PG0 0x00 // LED Control Register
#define ISSI3733_PG1 0x01 // PWM Register
#define ISSI3733_PG2 0x02 // Auto Breath Mode Register
#define ISSI3733_PG3 0x03 // Function Register
#define ISSI3733_PG_ONOFF ISSI3733_PG0
#define ISSI3733_PG_OR ISSI3733_PG0
@ -51,88 +51,88 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define ISSI3733_PG_ABM ISSI3733_PG2
#define ISSI3733_PG_FN ISSI3733_PG3
#define ISSI3733_CR 0x00 //Configuration Register
#define ISSI3733_CR 0x00 // Configuration Register
//PG3: Configuration Register: Synchronize Configuration
#define ISSI3733_CR_SYNC_MASTER 0x40 //Master
#define ISSI3733_CR_SYNC_SLAVE 0x80 //Slave
#define ISSI3733_CR_SYNC_HIGH_IMP 0xC0 //High Impedance
// PG3: Configuration Register: Synchronize Configuration
#define ISSI3733_CR_SYNC_MASTER 0x40 // Master
#define ISSI3733_CR_SYNC_SLAVE 0x80 // Slave
#define ISSI3733_CR_SYNC_HIGH_IMP 0xC0 // High Impedance
//PG3: Configuration Register: Open/Short Detection Enable Bit
// PG3: Configuration Register: Open/Short Detection Enable Bit
//#define ISSI3733_CR_OSD_DISABLE 0x00 //Disable open/short detection
#define ISSI3733_CR_OSD_ENABLE 0x04 //Enable open/short detection
#define ISSI3733_CR_OSD_ENABLE 0x04 // Enable open/short detection
//PG3: Configuration Register: Auto Breath Enable
// PG3: Configuration Register: Auto Breath Enable
//#define ISSI3733_CR_B_EN_PWM 0x00 //PWM Mode Enable
#define ISSI3733_CR_B_EN_AUTO 0x02 //Auto Breath Mode Enable
#define ISSI3733_CR_B_EN_AUTO 0x02 // Auto Breath Mode Enable
//PG3: Configuration Register: Software Shutdown Control
// PG3: Configuration Register: Software Shutdown Control
//#define ISSI3733_CR_SSD_SHUTDOWN 0x00 //Software shutdown
#define ISSI3733_CR_SSD_NORMAL 0x01 //Normal operation
#define ISSI3733_CR_SSD_NORMAL 0x01 // Normal operation
#define ISSI3733_GCCR 0x01 //Global Current Control Register
#define ISSI3733_GCCR 0x01 // Global Current Control Register
//1 Byte, Iout = (GCC / 256) * (840 / Rext)
//TODO: Give user define for Rext
// 1 Byte, Iout = (GCC / 256) * (840 / Rext)
// TODO: Give user define for Rext
//PG3: Auto Breath Control Register 1
#define ISSI3733_ABCR1_ABM1 0x02 //Auto Breath Control Register 1 of ABM-1
#define ISSI3733_ABCR1_ABM2 0x06 //Auto Breath Control Register 1 of ABM-2
#define ISSI3733_ABCR1_ABM3 0x0A //Auto Breath Control Register 1 of ABM-3
// PG3: Auto Breath Control Register 1
#define ISSI3733_ABCR1_ABM1 0x02 // Auto Breath Control Register 1 of ABM-1
#define ISSI3733_ABCR1_ABM2 0x06 // Auto Breath Control Register 1 of ABM-2
#define ISSI3733_ABCR1_ABM3 0x0A // Auto Breath Control Register 1 of ABM-3
//Rise time
#define ISSI3733_ABCR1_T1_0021 0x00 //0.21s
#define ISSI3733_ABCR1_T1_0042 0x20 //0.42s
#define ISSI3733_ABCR1_T1_0084 0x40 //0.84s
#define ISSI3733_ABCR1_T1_0168 0x60 //1.68s
#define ISSI3733_ABCR1_T1_0336 0x80 //3.36s
#define ISSI3733_ABCR1_T1_0672 0xA0 //6.72s
#define ISSI3733_ABCR1_T1_1344 0xC0 //13.44s
#define ISSI3733_ABCR1_T1_2688 0xE0 //26.88s
// Rise time
#define ISSI3733_ABCR1_T1_0021 0x00 // 0.21s
#define ISSI3733_ABCR1_T1_0042 0x20 // 0.42s
#define ISSI3733_ABCR1_T1_0084 0x40 // 0.84s
#define ISSI3733_ABCR1_T1_0168 0x60 // 1.68s
#define ISSI3733_ABCR1_T1_0336 0x80 // 3.36s
#define ISSI3733_ABCR1_T1_0672 0xA0 // 6.72s
#define ISSI3733_ABCR1_T1_1344 0xC0 // 13.44s
#define ISSI3733_ABCR1_T1_2688 0xE0 // 26.88s
//Max value time
#define ISSI3733_ABCR1_T2_0000 0x00 //0s
#define ISSI3733_ABCR1_T2_0021 0x02 //0.21s
#define ISSI3733_ABCR1_T2_0042 0x04 //0.42s
#define ISSI3733_ABCR1_T2_0084 0x06 //0.84s
#define ISSI3733_ABCR1_T2_0168 0x08 //1.68s
#define ISSI3733_ABCR1_T2_0336 0x0A //3.36s
#define ISSI3733_ABCR1_T2_0672 0x0C //6.72s
#define ISSI3733_ABCR1_T2_1344 0x0E //13.44s
#define ISSI3733_ABCR1_T2_2688 0x10 //26.88s
// Max value time
#define ISSI3733_ABCR1_T2_0000 0x00 // 0s
#define ISSI3733_ABCR1_T2_0021 0x02 // 0.21s
#define ISSI3733_ABCR1_T2_0042 0x04 // 0.42s
#define ISSI3733_ABCR1_T2_0084 0x06 // 0.84s
#define ISSI3733_ABCR1_T2_0168 0x08 // 1.68s
#define ISSI3733_ABCR1_T2_0336 0x0A // 3.36s
#define ISSI3733_ABCR1_T2_0672 0x0C // 6.72s
#define ISSI3733_ABCR1_T2_1344 0x0E // 13.44s
#define ISSI3733_ABCR1_T2_2688 0x10 // 26.88s
//PG3: Auto Breath Control Register 2
#define ISSI3733_ABCR2_ABM1 0x03 //Auto Breath Control Register 2 of ABM-1
#define ISSI3733_ABCR2_ABM2 0x07 //Auto Breath Control Register 2 of ABM-2
#define ISSI3733_ABCR2_ABM3 0x0B //Auto Breath Control Register 2 of ABM-3
// PG3: Auto Breath Control Register 2
#define ISSI3733_ABCR2_ABM1 0x03 // Auto Breath Control Register 2 of ABM-1
#define ISSI3733_ABCR2_ABM2 0x07 // Auto Breath Control Register 2 of ABM-2
#define ISSI3733_ABCR2_ABM3 0x0B // Auto Breath Control Register 2 of ABM-3
//Fall time
#define ISSI3733_ABCR2_T3_0021 0x00 //0.21s
#define ISSI3733_ABCR2_T3_0042 0x20 //0.42s
#define ISSI3733_ABCR2_T3_0084 0x40 //0.84s
#define ISSI3733_ABCR2_T3_0168 0x60 //1.68s
#define ISSI3733_ABCR2_T3_0336 0x80 //3.36s
#define ISSI3733_ABCR2_T3_0672 0xA0 //6.72s
#define ISSI3733_ABCR2_T3_1344 0xC0 //13.44s
#define ISSI3733_ABCR2_T3_2688 0xE0 //26.88s
// Fall time
#define ISSI3733_ABCR2_T3_0021 0x00 // 0.21s
#define ISSI3733_ABCR2_T3_0042 0x20 // 0.42s
#define ISSI3733_ABCR2_T3_0084 0x40 // 0.84s
#define ISSI3733_ABCR2_T3_0168 0x60 // 1.68s
#define ISSI3733_ABCR2_T3_0336 0x80 // 3.36s
#define ISSI3733_ABCR2_T3_0672 0xA0 // 6.72s
#define ISSI3733_ABCR2_T3_1344 0xC0 // 13.44s
#define ISSI3733_ABCR2_T3_2688 0xE0 // 26.88s
//Min value time
#define ISSI3733_ABCR2_T4_0000 0x00 //0s
#define ISSI3733_ABCR2_T4_0021 0x02 //0.21s
#define ISSI3733_ABCR2_T4_0042 0x04 //0.42s
#define ISSI3733_ABCR2_T4_0084 0x06 //0.84s
#define ISSI3733_ABCR2_T4_0168 0x08 //1.68s
#define ISSI3733_ABCR2_T4_0336 0x0A //3.36s
#define ISSI3733_ABCR2_T4_0672 0x0C //6.72s
#define ISSI3733_ABCR2_T4_1344 0x0E //13.44s
#define ISSI3733_ABCR2_T4_2688 0x10 //26.88s
#define ISSI3733_ABCR2_T4_5376 0x12 //53.76s
#define ISSI3733_ABCR2_T4_10752 0x14 //107.52s
// Min value time
#define ISSI3733_ABCR2_T4_0000 0x00 // 0s
#define ISSI3733_ABCR2_T4_0021 0x02 // 0.21s
#define ISSI3733_ABCR2_T4_0042 0x04 // 0.42s
#define ISSI3733_ABCR2_T4_0084 0x06 // 0.84s
#define ISSI3733_ABCR2_T4_0168 0x08 // 1.68s
#define ISSI3733_ABCR2_T4_0336 0x0A // 3.36s
#define ISSI3733_ABCR2_T4_0672 0x0C // 6.72s
#define ISSI3733_ABCR2_T4_1344 0x0E // 13.44s
#define ISSI3733_ABCR2_T4_2688 0x10 // 26.88s
#define ISSI3733_ABCR2_T4_5376 0x12 // 53.76s
#define ISSI3733_ABCR2_T4_10752 0x14 // 107.52s
//PG3: Auto Breath Control Register 3
#define ISSI3733_ABCR3_ABM1 0x04 //Auto Breath Control Register 3 of ABM-1
#define ISSI3733_ABCR3_ABM2 0x08 //Auto Breath Control Register 3 of ABM-2
#define ISSI3733_ABCR3_ABM3 0x0C //Auto Breath Control Register 3 of ABM-3
// PG3: Auto Breath Control Register 3
#define ISSI3733_ABCR3_ABM1 0x04 // Auto Breath Control Register 3 of ABM-1
#define ISSI3733_ABCR3_ABM2 0x08 // Auto Breath Control Register 3 of ABM-2
#define ISSI3733_ABCR3_ABM3 0x0C // Auto Breath Control Register 3 of ABM-3
#define ISSI3733_ABCR3_LTA_LOOP_ENDLESS 0x00
#define ISSI3733_ABCR3_LTA_LOOP_1 0x01
@ -151,51 +151,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define ISSI3733_ABCR3_LTA_LOOP_14 0x0E
#define ISSI3733_ABCR3_LTA_LOOP_15 0x0F
//Loop Begin
// Loop Begin
#define ISSI3733_ABCR3_LB_T1 0x00
#define ISSI3733_ABCR3_LB_T2 0x10
#define ISSI3733_ABCR3_LB_T3 0x20
#define ISSI3733_ABCR3_LB_T4 0x30
//Loop End
#define ISSI3733_ABCR3_LE_T3 0x00 //End at Off state
#define ISSI3733_ABCR3_LE_T1 0x40 //End at On State
// Loop End
#define ISSI3733_ABCR3_LE_T3 0x00 // End at Off state
#define ISSI3733_ABCR3_LE_T1 0x40 // End at On State
//PG3: Auto Breath Control Register 4
#define ISSI3733_ABCR4_ABM1 0x05 //Auto Breath Control Register 4 of ABM-1
#define ISSI3733_ABCR4_ABM2 0x09 //Auto Breath Control Register 4 of ABM-2
#define ISSI3733_ABCR4_ABM3 0x0D //Auto Breath Control Register 4 of ABM-3
// PG3: Auto Breath Control Register 4
#define ISSI3733_ABCR4_ABM1 0x05 // Auto Breath Control Register 4 of ABM-1
#define ISSI3733_ABCR4_ABM2 0x09 // Auto Breath Control Register 4 of ABM-2
#define ISSI3733_ABCR4_ABM3 0x0D // Auto Breath Control Register 4 of ABM-3
#define ISSI3733_ABCR4_LTB_LOOP_ENDLESS 0x00
//Or 8bit loop times
// Or 8bit loop times
//PG3: Time Update Register
// PG3: Time Update Register
#define ISSI3733_TUR 0x0E
#define ISSI3733_TUR_UPDATE 0x00 //Write to update 02h~0Dh time registers after configuring
#define ISSI3733_TUR_UPDATE 0x00 // Write to update 02h~0Dh time registers after configuring
//PG3: SWy Pull-Up Resistor Selection Register
// PG3: SWy Pull-Up Resistor Selection Register
#define ISSI3733_SWYR_PUR 0x0F
#define ISSI3733_SWYR_PUR_NONE 0x00 //No pull-up resistor
#define ISSI3733_SWYR_PUR_500 0x01 //0.5k Ohm
#define ISSI3733_SWYR_PUR_1000 0x02 //1.0k Ohm
#define ISSI3733_SWYR_PUR_2000 0x03 //2.0k Ohm
#define ISSI3733_SWYR_PUR_4000 0x04 //4.0k Ohm
#define ISSI3733_SWYR_PUR_8000 0x05 //8.0k Ohm
#define ISSI3733_SWYR_PUR_16000 0x06 //16k Ohm
#define ISSI3733_SWYR_PUR_32000 0x07 //32k Ohm
#define ISSI3733_SWYR_PUR_NONE 0x00 // No pull-up resistor
#define ISSI3733_SWYR_PUR_500 0x01 // 0.5k Ohm
#define ISSI3733_SWYR_PUR_1000 0x02 // 1.0k Ohm
#define ISSI3733_SWYR_PUR_2000 0x03 // 2.0k Ohm
#define ISSI3733_SWYR_PUR_4000 0x04 // 4.0k Ohm
#define ISSI3733_SWYR_PUR_8000 0x05 // 8.0k Ohm
#define ISSI3733_SWYR_PUR_16000 0x06 // 16k Ohm
#define ISSI3733_SWYR_PUR_32000 0x07 // 32k Ohm
//PG3: CSx Pull-Down Resistor Selection Register
// PG3: CSx Pull-Down Resistor Selection Register
#define ISSI3733_CSXR_PDR 0x10
#define ISSI3733_CSXR_PDR_NONE 0x00 //No pull-down resistor
#define ISSI3733_CSXR_PDR_500 0x01 //0.5k Ohm
#define ISSI3733_CSXR_PDR_1000 0x02 //1.0k Ohm
#define ISSI3733_CSXR_PDR_2000 0x03 //2.0k Ohm
#define ISSI3733_CSXR_PDR_4000 0x04 //4.0k Ohm
#define ISSI3733_CSXR_PDR_8000 0x05 //8.0k Ohm
#define ISSI3733_CSXR_PDR_16000 0x06 //16k Ohm
#define ISSI3733_CSXR_PDR_32000 0x07 //32k Ohm
#define ISSI3733_CSXR_PDR_NONE 0x00 // No pull-down resistor
#define ISSI3733_CSXR_PDR_500 0x01 // 0.5k Ohm
#define ISSI3733_CSXR_PDR_1000 0x02 // 1.0k Ohm
#define ISSI3733_CSXR_PDR_2000 0x03 // 2.0k Ohm
#define ISSI3733_CSXR_PDR_4000 0x04 // 4.0k Ohm
#define ISSI3733_CSXR_PDR_8000 0x05 // 8.0k Ohm
#define ISSI3733_CSXR_PDR_16000 0x06 // 16k Ohm
#define ISSI3733_CSXR_PDR_32000 0x07 // 32k Ohm
//PG3: Reset Register
#define ISSI3733_RR 0x11 //Read to reset all registers to default values
// PG3: Reset Register
#define ISSI3733_RR 0x11 // Read to reset all registers to default values
#endif //_ISSI3733_DRIVER_H_
#endif //_ISSI3733_DRIVER_H_

View file

@ -22,24 +22,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <math.h>
#ifdef USE_MASSDROP_CONFIGURATOR
__attribute__((weak))
led_instruction_t led_instructions[] = { { .end = 1 } };
static void led_matrix_massdrop_config_override(int i);
#endif // USE_MASSDROP_CONFIGURATOR
__attribute__((weak)) led_instruction_t led_instructions[] = {{.end = 1}};
static void led_matrix_massdrop_config_override(int i);
#endif // USE_MASSDROP_CONFIGURATOR
void SERCOM1_0_Handler( void )
{
if (SERCOM1->I2CM.INTFLAG.bit.ERROR)
{
void SERCOM1_0_Handler(void) {
if (SERCOM1->I2CM.INTFLAG.bit.ERROR) {
SERCOM1->I2CM.INTFLAG.reg = SERCOM_I2CM_INTENCLR_ERROR;
}
}
void DMAC_0_Handler( void )
{
if (DMAC->Channel[0].CHINTFLAG.bit.TCMPL)
{
void DMAC_0_Handler(void) {
if (DMAC->Channel[0].CHINTFLAG.bit.TCMPL) {
DMAC->Channel[0].CHINTFLAG.reg = DMAC_CHINTENCLR_TCMPL;
i2c1_stop();
@ -51,8 +45,7 @@ void DMAC_0_Handler( void )
return;
}
if (DMAC->Channel[0].CHINTFLAG.bit.TERR)
{
if (DMAC->Channel[0].CHINTFLAG.bit.TERR) {
DMAC->Channel[0].CHINTFLAG.reg = DMAC_CHINTENCLR_TERR;
}
}
@ -60,118 +53,109 @@ void DMAC_0_Handler( void )
issi3733_driver_t issidrv[ISSI3733_DRIVER_COUNT];
issi3733_led_t led_map[ISSI3733_LED_COUNT] = ISSI3733_LED_MAP;
RGB led_buffer[ISSI3733_LED_COUNT];
RGB led_buffer[ISSI3733_LED_COUNT];
uint8_t gcr_desired;
uint8_t gcr_actual;
uint8_t gcr_actual_last;
#ifdef USE_MASSDROP_CONFIGURATOR
uint8_t gcr_breathe;
float breathe_mult;
float pomod;
float breathe_mult;
float pomod;
#endif
#define ACT_GCR_NONE 0
#define ACT_GCR_INC 1
#define ACT_GCR_DEC 2
#define ACT_GCR_NONE 0
#define ACT_GCR_INC 1
#define ACT_GCR_DEC 2
#define LED_GCR_STEP_AUTO 2
static uint8_t gcr_min_counter;
static uint8_t v_5v_cat_hit;
//WARNING: Automatic GCR is in place to prevent USB shutdown and LED driver overloading
void gcr_compute(void)
{
uint8_t action = ACT_GCR_NONE;
// WARNING: Automatic GCR is in place to prevent USB shutdown and LED driver overloading
void gcr_compute(void) {
uint8_t action = ACT_GCR_NONE;
uint8_t gcr_use = gcr_desired;
#ifdef USE_MASSDROP_CONFIGURATOR
if (led_animation_breathing)
{
if (led_animation_breathing) {
gcr_use = gcr_breathe;
}
#endif
//If the 5v takes a catastrophic hit, disable the LED drivers briefly, assert auto gcr mode, min gcr and let the auto take over
if (v_5v < V5_CAT)
{
// If the 5v takes a catastrophic hit, disable the LED drivers briefly, assert auto gcr mode, min gcr and let the auto take over
if (v_5v < V5_CAT) {
I2C3733_Control_Set(0);
//CDC_print("USB: WARNING: 5V catastrophic level reached! Disabling LED drivers!\r\n"); //Blocking print is bad here!
v_5v_cat_hit = 20; //~100ms recover
gcr_actual = 0; //Minimize GCR
usb_gcr_auto = 1; //Force auto mode enabled
// CDC_print("USB: WARNING: 5V catastrophic level reached! Disabling LED drivers!\r\n"); //Blocking print is bad here!
v_5v_cat_hit = 20; //~100ms recover
gcr_actual = 0; // Minimize GCR
usb_gcr_auto = 1; // Force auto mode enabled
return;
}
else if (v_5v_cat_hit > 1)
{
} else if (v_5v_cat_hit > 1) {
v_5v_cat_hit--;
return;
}
else if (v_5v_cat_hit == 1)
{
} else if (v_5v_cat_hit == 1) {
I2C3733_Control_Set(1);
CDC_print("USB: WARNING: Re-enabling LED drivers\r\n");
v_5v_cat_hit = 0;
return;
}
if (usb_gcr_auto)
{
if (v_5v_avg < V5_LOW) action = ACT_GCR_DEC;
else if (v_5v_avg > V5_HIGH && gcr_actual < gcr_use) action = ACT_GCR_INC;
else if (gcr_actual > gcr_use) action = ACT_GCR_DEC;
}
else
{
if (gcr_actual < gcr_use) action = ACT_GCR_INC;
else if (gcr_actual > gcr_use) action = ACT_GCR_DEC;
if (usb_gcr_auto) {
if (v_5v_avg < V5_LOW)
action = ACT_GCR_DEC;
else if (v_5v_avg > V5_HIGH && gcr_actual < gcr_use)
action = ACT_GCR_INC;
else if (gcr_actual > gcr_use)
action = ACT_GCR_DEC;
} else {
if (gcr_actual < gcr_use)
action = ACT_GCR_INC;
else if (gcr_actual > gcr_use)
action = ACT_GCR_DEC;
}
if (action == ACT_GCR_NONE)
{
if (action == ACT_GCR_NONE) {
gcr_min_counter = 0;
}
else if (action == ACT_GCR_INC)
{
if (LED_GCR_STEP_AUTO > LED_GCR_MAX - gcr_actual) gcr_actual = LED_GCR_MAX; //Obey max and prevent wrapping
else gcr_actual += LED_GCR_STEP_AUTO;
} else if (action == ACT_GCR_INC) {
if (LED_GCR_STEP_AUTO > LED_GCR_MAX - gcr_actual)
gcr_actual = LED_GCR_MAX; // Obey max and prevent wrapping
else
gcr_actual += LED_GCR_STEP_AUTO;
gcr_min_counter = 0;
}
else if (action == ACT_GCR_DEC)
{
if (LED_GCR_STEP_AUTO > gcr_actual) //Prevent wrapping
} else if (action == ACT_GCR_DEC) {
if (LED_GCR_STEP_AUTO > gcr_actual) // Prevent wrapping
{
gcr_actual = 0;
//At this point, power can no longer be cut from the LED drivers, so focus on cutting out extra port if active
if (usb_extra_state != USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) //If not in a wait for replug state
// At this point, power can no longer be cut from the LED drivers, so focus on cutting out extra port if active
if (usb_extra_state != USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) // If not in a wait for replug state
{
if (usb_extra_state == USB_EXTRA_STATE_ENABLED) //If extra usb is enabled
if (usb_extra_state == USB_EXTRA_STATE_ENABLED) // If extra usb is enabled
{
gcr_min_counter++;
if (gcr_min_counter > 200) //5ms per check = 1s delay
if (gcr_min_counter > 200) // 5ms per check = 1s delay
{
USB_ExtraSetState(USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG);
usb_extra_manual = 0; //Force disable manual mode of extra port
if (usb_extra_manual) CDC_print("USB: Disabling extra port until replug and manual mode toggle!\r\n");
else CDC_print("USB: Disabling extra port until replug!\r\n");
usb_extra_manual = 0; // Force disable manual mode of extra port
if (usb_extra_manual)
CDC_print("USB: Disabling extra port until replug and manual mode toggle!\r\n");
else
CDC_print("USB: Disabling extra port until replug!\r\n");
}
}
}
}
else
{
//Power successfully cut back from LED drivers
} else {
// Power successfully cut back from LED drivers
gcr_actual -= LED_GCR_STEP_AUTO;
gcr_min_counter = 0;
#ifdef USE_MASSDROP_CONFIGURATOR
//If breathe mode is active, the top end can fluctuate if the host can not supply enough current
//So set the breathe GCR to where it becomes stable
if (led_animation_breathing == 1)
{
// If breathe mode is active, the top end can fluctuate if the host can not supply enough current
// So set the breathe GCR to where it becomes stable
if (led_animation_breathing == 1) {
gcr_breathe = gcr_actual;
//PS: At this point, setting breathing to exhale makes a noticebly shorter cycle
// PS: At this point, setting breathing to exhale makes a noticebly shorter cycle
// and the same would happen maybe one or two more times. Therefore I'm favoring
// powering through one full breathe and letting gcr settle completely
}
@ -180,47 +164,40 @@ void gcr_compute(void)
}
}
void issi3733_prepare_arrays(void)
{
memset(issidrv,0,sizeof(issi3733_driver_t) * ISSI3733_DRIVER_COUNT);
void issi3733_prepare_arrays(void) {
memset(issidrv, 0, sizeof(issi3733_driver_t) * ISSI3733_DRIVER_COUNT);
int i;
int i;
uint8_t addrs[ISSI3733_DRIVER_COUNT] = ISSI3773_DRIVER_ADDRESSES;
for (i=0;i<ISSI3733_DRIVER_COUNT;i++)
{
for (i = 0; i < ISSI3733_DRIVER_COUNT; i++) {
issidrv[i].addr = addrs[i];
}
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
{
//BYTE: 1 + (SW-1)*16 + (CS-1)
led_map[i].rgb.g = issidrv[led_map[i].adr.drv-1].pwm + 1 + ((led_map[i].adr.swg-1)*16 + (led_map[i].adr.cs-1));
led_map[i].rgb.r = issidrv[led_map[i].adr.drv-1].pwm + 1 + ((led_map[i].adr.swr-1)*16 + (led_map[i].adr.cs-1));
led_map[i].rgb.b = issidrv[led_map[i].adr.drv-1].pwm + 1 + ((led_map[i].adr.swb-1)*16 + (led_map[i].adr.cs-1));
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
// BYTE: 1 + (SW-1)*16 + (CS-1)
led_map[i].rgb.g = issidrv[led_map[i].adr.drv - 1].pwm + 1 + ((led_map[i].adr.swg - 1) * 16 + (led_map[i].adr.cs - 1));
led_map[i].rgb.r = issidrv[led_map[i].adr.drv - 1].pwm + 1 + ((led_map[i].adr.swr - 1) * 16 + (led_map[i].adr.cs - 1));
led_map[i].rgb.b = issidrv[led_map[i].adr.drv - 1].pwm + 1 + ((led_map[i].adr.swb - 1) * 16 + (led_map[i].adr.cs - 1));
//BYTE: 1 + (SW-1)*2 + (CS-1)/8
//BIT: (CS-1)%8
*(issidrv[led_map[i].adr.drv-1].onoff + 1 + (led_map[i].adr.swg-1)*2+(led_map[i].adr.cs-1)/8) |= (1<<((led_map[i].adr.cs-1)%8));
*(issidrv[led_map[i].adr.drv-1].onoff + 1 + (led_map[i].adr.swr-1)*2+(led_map[i].adr.cs-1)/8) |= (1<<((led_map[i].adr.cs-1)%8));
*(issidrv[led_map[i].adr.drv-1].onoff + 1 + (led_map[i].adr.swb-1)*2+(led_map[i].adr.cs-1)/8) |= (1<<((led_map[i].adr.cs-1)%8));
// BYTE: 1 + (SW-1)*2 + (CS-1)/8
// BIT: (CS-1)%8
*(issidrv[led_map[i].adr.drv - 1].onoff + 1 + (led_map[i].adr.swg - 1) * 2 + (led_map[i].adr.cs - 1) / 8) |= (1 << ((led_map[i].adr.cs - 1) % 8));
*(issidrv[led_map[i].adr.drv - 1].onoff + 1 + (led_map[i].adr.swr - 1) * 2 + (led_map[i].adr.cs - 1) / 8) |= (1 << ((led_map[i].adr.cs - 1) % 8));
*(issidrv[led_map[i].adr.drv - 1].onoff + 1 + (led_map[i].adr.swb - 1) * 2 + (led_map[i].adr.cs - 1) / 8) |= (1 << ((led_map[i].adr.cs - 1) % 8));
}
}
void led_matrix_prepare(void)
{
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
{
void led_matrix_prepare(void) {
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
*led_map[i].rgb.r = 0;
*led_map[i].rgb.g = 0;
*led_map[i].rgb.b = 0;
}
}
void led_set_one(int i, uint8_t r, uint8_t g, uint8_t b)
{
if (i < ISSI3733_LED_COUNT)
{
void led_set_one(int i, uint8_t r, uint8_t g, uint8_t b) {
if (i < ISSI3733_LED_COUNT) {
#ifdef USE_MASSDROP_CONFIGURATOR
led_matrix_massdrop_config_override(i);
#else
@ -231,16 +208,13 @@ void led_set_one(int i, uint8_t r, uint8_t g, uint8_t b)
}
}
void led_set_all(uint8_t r, uint8_t g, uint8_t b)
{
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
{
led_set_one(i, r, g, b);
}
void led_set_all(uint8_t r, uint8_t g, uint8_t b) {
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
led_set_one(i, r, g, b);
}
}
void init(void)
{
void init(void) {
DBGC(DC_LED_MATRIX_INIT_BEGIN);
issi3733_prepare_arrays();
@ -248,25 +222,28 @@ void init(void)
led_matrix_prepare();
gcr_min_counter = 0;
v_5v_cat_hit = 0;
v_5v_cat_hit = 0;
DBGC(DC_LED_MATRIX_INIT_COMPLETE);
}
void flush(void)
{
void flush(void) {
#ifdef USE_MASSDROP_CONFIGURATOR
if (!led_enabled) { return; } //Prevent calculations and I2C traffic if LED drivers are not enabled
if (!led_enabled) {
return;
} // Prevent calculations and I2C traffic if LED drivers are not enabled
#else
if (!sr_exp_data.bit.SDB_N) { return; } //Prevent calculations and I2C traffic if LED drivers are not enabled
if (!sr_exp_data.bit.SDB_N) {
return;
} // Prevent calculations and I2C traffic if LED drivers are not enabled
#endif
// Wait for previous transfer to complete
while (i2c_led_q_running) {}
while (i2c_led_q_running) {
}
// Copy buffer to live DMA region
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
{
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
*led_map[i].rgb.r = led_buffer[i].r;
*led_map[i].rgb.g = led_buffer[i].g;
*led_map[i].rgb.b = led_buffer[i].b;
@ -275,8 +252,7 @@ void flush(void)
#ifdef USE_MASSDROP_CONFIGURATOR
breathe_mult = 1;
if (led_animation_breathing)
{
if (led_animation_breathing) {
//+60us 119 LED
led_animation_breathe_cur += BREATHE_STEP * breathe_dir;
@ -285,76 +261,65 @@ void flush(void)
else if (led_animation_breathe_cur <= BREATHE_MIN_STEP)
breathe_dir = 1;
//Brightness curve created for 256 steps, 0 - ~98%
// Brightness curve created for 256 steps, 0 - ~98%
breathe_mult = 0.000015 * led_animation_breathe_cur * led_animation_breathe_cur;
if (breathe_mult > 1) breathe_mult = 1;
else if (breathe_mult < 0) breathe_mult = 0;
if (breathe_mult > 1)
breathe_mult = 1;
else if (breathe_mult < 0)
breathe_mult = 0;
}
//This should only be performed once per frame
// This should only be performed once per frame
pomod = (float)((g_rgb_counters.tick / 10) % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed;
pomod *= 100.0f;
pomod = (uint32_t)pomod % 10000;
pomod /= 100.0f;
#endif // USE_MASSDROP_CONFIGURATOR
#endif // USE_MASSDROP_CONFIGURATOR
uint8_t drvid;
//NOTE: GCR does not need to be timed with LED processing, but there is really no harm
if (gcr_actual != gcr_actual_last)
{
for (drvid=0;drvid<ISSI3733_DRIVER_COUNT;drvid++)
I2C_LED_Q_GCR(drvid); //Queue data
// NOTE: GCR does not need to be timed with LED processing, but there is really no harm
if (gcr_actual != gcr_actual_last) {
for (drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++) I2C_LED_Q_GCR(drvid); // Queue data
gcr_actual_last = gcr_actual;
}
for (drvid=0;drvid<ISSI3733_DRIVER_COUNT;drvid++)
I2C_LED_Q_PWM(drvid); //Queue data
for (drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++) I2C_LED_Q_PWM(drvid); // Queue data
i2c_led_q_run();
}
void led_matrix_indicators(void)
{
void led_matrix_indicators(void) {
uint8_t kbled = keyboard_leds();
if (kbled && rgb_matrix_config.enable)
{
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++)
{
if (kbled && rgb_matrix_config.enable) {
for (uint8_t i = 0; i < ISSI3733_LED_COUNT; i++) {
if (
#if USB_LED_NUM_LOCK_SCANCODE != 255
(led_map[i].scan == USB_LED_NUM_LOCK_SCANCODE && (kbled & (1<<USB_LED_NUM_LOCK))) ||
#endif //NUM LOCK
#if USB_LED_CAPS_LOCK_SCANCODE != 255
(led_map[i].scan == USB_LED_CAPS_LOCK_SCANCODE && (kbled & (1<<USB_LED_CAPS_LOCK))) ||
#endif //CAPS LOCK
#if USB_LED_SCROLL_LOCK_SCANCODE != 255
(led_map[i].scan == USB_LED_SCROLL_LOCK_SCANCODE && (kbled & (1<<USB_LED_SCROLL_LOCK))) ||
#endif //SCROLL LOCK
#if USB_LED_COMPOSE_SCANCODE != 255
(led_map[i].scan == USB_LED_COMPOSE_SCANCODE && (kbled & (1<<USB_LED_COMPOSE))) ||
#endif //COMPOSE
#if USB_LED_KANA_SCANCODE != 255
(led_map[i].scan == USB_LED_KANA_SCANCODE && (kbled & (1<<USB_LED_KANA))) ||
#endif //KANA
(0))
{
#if USB_LED_NUM_LOCK_SCANCODE != 255
(led_map[i].scan == USB_LED_NUM_LOCK_SCANCODE && (kbled & (1 << USB_LED_NUM_LOCK))) ||
#endif // NUM LOCK
#if USB_LED_CAPS_LOCK_SCANCODE != 255
(led_map[i].scan == USB_LED_CAPS_LOCK_SCANCODE && (kbled & (1 << USB_LED_CAPS_LOCK))) ||
#endif // CAPS LOCK
#if USB_LED_SCROLL_LOCK_SCANCODE != 255
(led_map[i].scan == USB_LED_SCROLL_LOCK_SCANCODE && (kbled & (1 << USB_LED_SCROLL_LOCK))) ||
#endif // SCROLL LOCK
#if USB_LED_COMPOSE_SCANCODE != 255
(led_map[i].scan == USB_LED_COMPOSE_SCANCODE && (kbled & (1 << USB_LED_COMPOSE))) ||
#endif // COMPOSE
#if USB_LED_KANA_SCANCODE != 255
(led_map[i].scan == USB_LED_KANA_SCANCODE && (kbled & (1 << USB_LED_KANA))) ||
#endif // KANA
(0)) {
led_buffer[i].r = 255 - led_buffer[i].r;
led_buffer[i].g = 255 - led_buffer[i].g;
led_buffer[i].b = 255 - led_buffer[i].b;
}
}
}
}
const rgb_matrix_driver_t rgb_matrix_driver = {
.init = init,
.flush = flush,
.set_color = led_set_one,
.set_color_all = led_set_all
};
const rgb_matrix_driver_t rgb_matrix_driver = {.init = init, .flush = flush, .set_color = led_set_one, .set_color_all = led_set_all};
/*==============================================================================
= Legacy Lighting Support =
@ -365,103 +330,100 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
// TODO?: wire these up to keymap.c
uint8_t led_animation_orientation = 0;
uint8_t led_animation_direction = 0;
uint8_t led_animation_breathing = 0;
uint8_t led_animation_id = 0;
float led_animation_speed = 4.0f;
uint8_t led_lighting_mode = LED_MODE_NORMAL;
uint8_t led_enabled = 1;
uint8_t led_animation_direction = 0;
uint8_t led_animation_breathing = 0;
uint8_t led_animation_id = 0;
float led_animation_speed = 4.0f;
uint8_t led_lighting_mode = LED_MODE_NORMAL;
uint8_t led_enabled = 1;
uint8_t led_animation_breathe_cur = BREATHE_MIN_STEP;
uint8_t breathe_dir = 1;
uint8_t breathe_dir = 1;
static void led_run_pattern(led_setup_t *f, float* ro, float* go, float* bo, float pos) {
static void led_run_pattern(led_setup_t* f, float* ro, float* go, float* bo, float pos) {
float po;
while (f->end != 1)
{
po = pos; //Reset po for new frame
while (f->end != 1) {
po = pos; // Reset po for new frame
//Add in any moving effects
if ((!led_animation_direction && f->ef & EF_SCR_R) || (led_animation_direction && (f->ef & EF_SCR_L)))
{
// Add in any moving effects
if ((!led_animation_direction && f->ef & EF_SCR_R) || (led_animation_direction && (f->ef & EF_SCR_L))) {
po -= pomod;
if (po > 100) po -= 100;
else if (po < 0) po += 100;
}
else if ((!led_animation_direction && f->ef & EF_SCR_L) || (led_animation_direction && (f->ef & EF_SCR_R)))
{
if (po > 100)
po -= 100;
else if (po < 0)
po += 100;
} else if ((!led_animation_direction && f->ef & EF_SCR_L) || (led_animation_direction && (f->ef & EF_SCR_R))) {
po += pomod;
if (po > 100) po -= 100;
else if (po < 0) po += 100;
if (po > 100)
po -= 100;
else if (po < 0)
po += 100;
}
//Check if LED's po is in current frame
if (po < f->hs) { f++; continue; }
if (po > f->he) { f++; continue; }
//note: < 0 or > 100 continue
// Check if LED's po is in current frame
if (po < f->hs) {
f++;
continue;
}
if (po > f->he) {
f++;
continue;
}
// note: < 0 or > 100 continue
//Calculate the po within the start-stop percentage for color blending
// Calculate the po within the start-stop percentage for color blending
po = (po - f->hs) / (f->he - f->hs);
//Add in any color effects
if (f->ef & EF_OVER)
{
*ro = (po * (f->re - f->rs)) + f->rs;// + 0.5;
*go = (po * (f->ge - f->gs)) + f->gs;// + 0.5;
*bo = (po * (f->be - f->bs)) + f->bs;// + 0.5;
}
else if (f->ef & EF_SUBTRACT)
{
*ro -= (po * (f->re - f->rs)) + f->rs;// + 0.5;
*go -= (po * (f->ge - f->gs)) + f->gs;// + 0.5;
*bo -= (po * (f->be - f->bs)) + f->bs;// + 0.5;
}
else
{
*ro += (po * (f->re - f->rs)) + f->rs;// + 0.5;
*go += (po * (f->ge - f->gs)) + f->gs;// + 0.5;
*bo += (po * (f->be - f->bs)) + f->bs;// + 0.5;
// Add in any color effects
if (f->ef & EF_OVER) {
*ro = (po * (f->re - f->rs)) + f->rs; // + 0.5;
*go = (po * (f->ge - f->gs)) + f->gs; // + 0.5;
*bo = (po * (f->be - f->bs)) + f->bs; // + 0.5;
} else if (f->ef & EF_SUBTRACT) {
*ro -= (po * (f->re - f->rs)) + f->rs; // + 0.5;
*go -= (po * (f->ge - f->gs)) + f->gs; // + 0.5;
*bo -= (po * (f->be - f->bs)) + f->bs; // + 0.5;
} else {
*ro += (po * (f->re - f->rs)) + f->rs; // + 0.5;
*go += (po * (f->ge - f->gs)) + f->gs; // + 0.5;
*bo += (po * (f->be - f->bs)) + f->bs; // + 0.5;
}
f++;
}
}
static void led_matrix_massdrop_config_override(int i)
{
static void led_matrix_massdrop_config_override(int i) {
float ro = 0;
float go = 0;
float bo = 0;
float po = (led_animation_orientation)
? (float)g_led_config.point[i].y / 64.f * 100
: (float)g_led_config.point[i].x / 224.f * 100;
float po = (led_animation_orientation) ? (float)g_led_config.point[i].y / 64.f * 100 : (float)g_led_config.point[i].x / 224.f * 100;
uint8_t highest_active_layer = biton32(layer_state);
if (led_lighting_mode == LED_MODE_KEYS_ONLY && HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) {
//Do not act on this LED
// Do not act on this LED
} else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && !HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) {
//Do not act on this LED
// Do not act on this LED
} else if (led_lighting_mode == LED_MODE_INDICATORS_ONLY) {
//Do not act on this LED (Only show indicators)
// Do not act on this LED (Only show indicators)
} else {
led_instruction_t* led_cur_instruction = led_instructions;
while (!led_cur_instruction->end) {
// Check if this applies to current layer
if ((led_cur_instruction->flags & LED_FLAG_MATCH_LAYER) &&
(led_cur_instruction->layer != highest_active_layer)) {
if ((led_cur_instruction->flags & LED_FLAG_MATCH_LAYER) && (led_cur_instruction->layer != highest_active_layer)) {
goto next_iter;
}
// Check if this applies to current index
if (led_cur_instruction->flags & LED_FLAG_MATCH_ID) {
uint8_t modid = i / 32; //Calculate which id# contains the led bit
uint32_t modidbit = 1 << (i % 32); //Calculate the bit within the id#
uint32_t *bitfield = &led_cur_instruction->id0 + modid; //Add modid as offset to id0 address. *bitfield is now idX of the led id
if (~(*bitfield) & modidbit) { //Check if led bit is not set in idX
uint8_t modid = i / 32; // Calculate which id# contains the led bit
uint32_t modidbit = 1 << (i % 32); // Calculate the bit within the id#
uint32_t* bitfield = &led_cur_instruction->id0 + modid; // Add modid as offset to id0 address. *bitfield is now idX of the led id
if (~(*bitfield) & modidbit) { // Check if led bit is not set in idX
goto next_iter;
}
}
@ -476,16 +438,24 @@ static void led_matrix_massdrop_config_override(int i)
led_run_pattern(led_setups[led_animation_id], &ro, &go, &bo, po);
}
next_iter:
led_cur_instruction++;
next_iter:
led_cur_instruction++;
}
if (ro > 255) ro = 255; else if (ro < 0) ro = 0;
if (go > 255) go = 255; else if (go < 0) go = 0;
if (bo > 255) bo = 255; else if (bo < 0) bo = 0;
if (ro > 255)
ro = 255;
else if (ro < 0)
ro = 0;
if (go > 255)
go = 255;
else if (go < 0)
go = 0;
if (bo > 255)
bo = 255;
else if (bo < 0)
bo = 0;
if (led_animation_breathing)
{
if (led_animation_breathing) {
ro *= breathe_mult;
go *= breathe_mult;
bo *= breathe_mult;
@ -497,4 +467,4 @@ static void led_matrix_massdrop_config_override(int i)
led_buffer[i].b = (uint8_t)bo;
}
#endif // USE_MASSDROP_CONFIGURATOR
#endif // USE_MASSDROP_CONFIGURATOR

View file

@ -20,20 +20,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "quantum.h"
//From keyboard
// From keyboard
#include "config_led.h"
//CS1-CS16 Current Source "Col"
// CS1-CS16 Current Source "Col"
#define ISSI3733_CS_COUNT 16
//SW1-SW12 Switch "Row"
// SW1-SW12 Switch "Row"
#define ISSI3733_SW_COUNT 12
#define ISSI3733_LED_RGB_COUNT ISSI3733_CS_COUNT * ISSI3733_SW_COUNT
#define ISSI3733_PG0_BYTES ISSI3733_LED_RGB_COUNT / 8 + 1 //+1 for first byte being memory start offset for I2C transfer
#define ISSI3733_PG1_BYTES ISSI3733_LED_RGB_COUNT + 1 //+1 for first byte being memory start offset for I2C transfer
#define ISSI3733_PG2_BYTES ISSI3733_LED_RGB_COUNT + 1 //+1 for first byte being memory start offset for I2C transfer
#define ISSI3733_PG3_BYTES 18 + 1 //+1 for first byte being memory start offset for I2C transfer
#define ISSI3733_LED_RGB_COUNT ISSI3733_CS_COUNT *ISSI3733_SW_COUNT
#define ISSI3733_PG0_BYTES ISSI3733_LED_RGB_COUNT / 8 + 1 //+1 for first byte being memory start offset for I2C transfer
#define ISSI3733_PG1_BYTES ISSI3733_LED_RGB_COUNT + 1 //+1 for first byte being memory start offset for I2C transfer
#define ISSI3733_PG2_BYTES ISSI3733_LED_RGB_COUNT + 1 //+1 for first byte being memory start offset for I2C transfer
#define ISSI3733_PG3_BYTES 18 + 1 //+1 for first byte being memory start offset for I2C transfer
#define ISSI3733_PG_ONOFF_BYTES ISSI3733_PG0_BYTES
#define ISSI3733_PG_OR_BYTES ISSI3733_PG0_BYTES
@ -43,38 +43,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define ISSI3733_PG_FN_BYTES ISSI3733_PG3_BYTES
typedef struct issi3733_driver_s {
uint8_t addr; //Address of the driver according to wiring "ISSI3733: Table 1 Slave Address"
uint8_t onoff[ISSI3733_PG_ONOFF_BYTES]; //PG0 - LED Control Register - LED On/Off Register
uint8_t open[ISSI3733_PG_OR_BYTES]; //PG0 - LED Control Register - LED Open Register
uint8_t shrt[ISSI3733_PG_SR_BYTES]; //PG0 - LED Control Register - LED Short Register
uint8_t pwm[ISSI3733_PG_PWM_BYTES]; //PG1 - PWM Register
uint8_t abm[ISSI3733_PG_ABM_BYTES]; //PG2 - Auto Breath Mode Register
uint8_t conf[ISSI3733_PG_FN_BYTES]; //PG3 - Function Register
uint8_t addr; // Address of the driver according to wiring "ISSI3733: Table 1 Slave Address"
uint8_t onoff[ISSI3733_PG_ONOFF_BYTES]; // PG0 - LED Control Register - LED On/Off Register
uint8_t open[ISSI3733_PG_OR_BYTES]; // PG0 - LED Control Register - LED Open Register
uint8_t shrt[ISSI3733_PG_SR_BYTES]; // PG0 - LED Control Register - LED Short Register
uint8_t pwm[ISSI3733_PG_PWM_BYTES]; // PG1 - PWM Register
uint8_t abm[ISSI3733_PG_ABM_BYTES]; // PG2 - Auto Breath Mode Register
uint8_t conf[ISSI3733_PG_FN_BYTES]; // PG3 - Function Register
} issi3733_driver_t;
typedef struct issi3733_rgb_s {
uint8_t *r; //Direct access into PWM data
uint8_t *g; //Direct access into PWM data
uint8_t *b; //Direct access into PWM data
uint8_t *r; // Direct access into PWM data
uint8_t *g; // Direct access into PWM data
uint8_t *b; // Direct access into PWM data
} issi3733_rgb_t;
typedef struct issi3733_rgb_adr_s {
uint8_t drv; //Driver from given list
uint8_t cs; //CS
uint8_t swr; //SW Red
uint8_t swg; //SW Green
uint8_t swb; //SW Blue
uint8_t drv; // Driver from given list
uint8_t cs; // CS
uint8_t swr; // SW Red
uint8_t swg; // SW Green
uint8_t swb; // SW Blue
} issi3733_rgb_adr_t;
typedef struct issi3733_led_s {
uint8_t id; //According to PCB ref
issi3733_rgb_t rgb; //PWM settings of R G B
issi3733_rgb_adr_t adr; //Hardware addresses
float x; //Physical position X
float y; //Physical position Y
float px; //Physical position X in percent
float py; //Physical position Y in percent
uint8_t scan; //Key scan code from wiring (set 0xFF if no key)
uint8_t id; // According to PCB ref
issi3733_rgb_t rgb; // PWM settings of R G B
issi3733_rgb_adr_t adr; // Hardware addresses
float x; // Physical position X
float y; // Physical position Y
float px; // Physical position X in percent
float py; // Physical position Y in percent
uint8_t scan; // Key scan code from wiring (set 0xFF if no key)
} issi3733_led_t;
extern issi3733_driver_t issidrv[ISSI3733_DRIVER_COUNT];
@ -92,67 +92,67 @@ void led_matrix_indicators(void);
#ifdef USE_MASSDROP_CONFIGURATOR
#define EF_NONE 0x00000000 //No effect
#define EF_OVER 0x00000001 //Overwrite any previous color information with new
#define EF_SCR_L 0x00000002 //Scroll left
#define EF_SCR_R 0x00000004 //Scroll right
#define EF_SUBTRACT 0x00000008 //Subtract color values
# define EF_NONE 0x00000000 // No effect
# define EF_OVER 0x00000001 // Overwrite any previous color information with new
# define EF_SCR_L 0x00000002 // Scroll left
# define EF_SCR_R 0x00000004 // Scroll right
# define EF_SUBTRACT 0x00000008 // Subtract color values
typedef struct led_setup_s {
float hs; //Band begin at percent
float he; //Band end at percent
uint8_t rs; //Red start value
uint8_t re; //Red end value
uint8_t gs; //Green start value
uint8_t ge; //Green end value
uint8_t bs; //Blue start value
uint8_t be; //Blue end value
uint32_t ef; //Animation and color effects
uint8_t end; //Set to signal end of the setup
float hs; // Band begin at percent
float he; // Band end at percent
uint8_t rs; // Red start value
uint8_t re; // Red end value
uint8_t gs; // Green start value
uint8_t ge; // Green end value
uint8_t bs; // Blue start value
uint8_t be; // Blue end value
uint32_t ef; // Animation and color effects
uint8_t end; // Set to signal end of the setup
} led_setup_t;
extern const uint8_t led_setups_count;
extern void *led_setups[];
extern void * led_setups[];
//LED Extra Instructions
#define LED_FLAG_NULL 0x00 //Matching and coloring not used (default)
#define LED_FLAG_MATCH_ID 0x01 //Match on the ID of the LED (set id#'s to desired bit pattern, first LED is id 1)
#define LED_FLAG_MATCH_LAYER 0x02 //Match on the current active layer (set layer to desired match layer)
#define LED_FLAG_USE_RGB 0x10 //Use a specific RGB value (set r, g, b to desired output color values)
#define LED_FLAG_USE_PATTERN 0x20 //Use a specific pattern ID (set pattern_id to desired output pattern)
#define LED_FLAG_USE_ROTATE_PATTERN 0x40 //Use pattern the user has cycled to manually
// LED Extra Instructions
# define LED_FLAG_NULL 0x00 // Matching and coloring not used (default)
# define LED_FLAG_MATCH_ID 0x01 // Match on the ID of the LED (set id#'s to desired bit pattern, first LED is id 1)
# define LED_FLAG_MATCH_LAYER 0x02 // Match on the current active layer (set layer to desired match layer)
# define LED_FLAG_USE_RGB 0x10 // Use a specific RGB value (set r, g, b to desired output color values)
# define LED_FLAG_USE_PATTERN 0x20 // Use a specific pattern ID (set pattern_id to desired output pattern)
# define LED_FLAG_USE_ROTATE_PATTERN 0x40 // Use pattern the user has cycled to manually
typedef struct led_instruction_s {
uint16_t flags; // Bitfield for LED instructions
uint32_t id0; // Bitwise id, IDs 0-31
uint32_t id1; // Bitwise id, IDs 32-63
uint32_t id2; // Bitwise id, IDs 64-95
uint32_t id3; // Bitwise id, IDs 96-127
uint8_t layer;
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t pattern_id;
uint8_t end;
uint16_t flags; // Bitfield for LED instructions
uint32_t id0; // Bitwise id, IDs 0-31
uint32_t id1; // Bitwise id, IDs 32-63
uint32_t id2; // Bitwise id, IDs 64-95
uint32_t id3; // Bitwise id, IDs 96-127
uint8_t layer;
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t pattern_id;
uint8_t end;
} led_instruction_t;
extern led_instruction_t led_instructions[];
extern uint8_t led_animation_breathing;
extern uint8_t led_animation_id;
extern float led_animation_speed;
extern float led_animation_speed;
extern uint8_t led_lighting_mode;
extern uint8_t led_enabled;
extern uint8_t led_animation_breathe_cur;
extern uint8_t led_animation_direction;
extern uint8_t breathe_dir;
#define LED_MODE_NORMAL 0 //Must be 0
#define LED_MODE_KEYS_ONLY 1
#define LED_MODE_NON_KEYS_ONLY 2
#define LED_MODE_INDICATORS_ONLY 3
#define LED_MODE_MAX_INDEX LED_MODE_INDICATORS_ONLY //Must be highest value
# define LED_MODE_NORMAL 0 // Must be 0
# define LED_MODE_KEYS_ONLY 1
# define LED_MODE_NON_KEYS_ONLY 2
# define LED_MODE_INDICATORS_ONLY 3
# define LED_MODE_MAX_INDEX LED_MODE_INDICATORS_ONLY // Must be highest value
#endif // USE_MASSDROP_CONFIGURATOR
#endif // USE_MASSDROP_CONFIGURATOR
#endif //_LED_MATRIX_H_
#endif //_LED_MATRIX_H_

View file

@ -17,106 +17,82 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef USE_MASSDROP_CONFIGURATOR
#include "led_matrix.h"
# include "led_matrix.h"
//Teal <-> Salmon
// Teal <-> Salmon
led_setup_t leds_teal_salmon[] = {
{ .hs = 0, .he = 33, .rs = 24, .re = 24, .gs = 215, .ge = 215, .bs = 204, .be = 204, .ef = EF_NONE },
{ .hs = 33, .he = 66, .rs = 24, .re = 255, .gs = 215, .ge = 114, .bs = 204, .be = 118, .ef = EF_NONE },
{ .hs = 66, .he = 100, .rs = 255, .re = 255, .gs = 114, .ge = 114, .bs = 118, .be = 118, .ef = EF_NONE },
{ .end = 1 },
{.hs = 0, .he = 33, .rs = 24, .re = 24, .gs = 215, .ge = 215, .bs = 204, .be = 204, .ef = EF_NONE},
{.hs = 33, .he = 66, .rs = 24, .re = 255, .gs = 215, .ge = 114, .bs = 204, .be = 118, .ef = EF_NONE},
{.hs = 66, .he = 100, .rs = 255, .re = 255, .gs = 114, .ge = 114, .bs = 118, .be = 118, .ef = EF_NONE},
{.end = 1},
};
//Yellow
// Yellow
led_setup_t leds_yellow[] = {
{ .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE },
{ .end = 1 },
{.hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE},
{.end = 1},
};
//Off
// Off
led_setup_t leds_off[] = {
{ .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE },
{ .end = 1 },
{.hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE},
{.end = 1},
};
//Red
// Red
led_setup_t leds_red[] = {
{ .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE },
{ .end = 1 },
{.hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE},
{.end = 1},
};
//Green
// Green
led_setup_t leds_green[] = {
{ .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE },
{ .end = 1 },
{.hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE},
{.end = 1},
};
//Blue
// Blue
led_setup_t leds_blue[] = {
{ .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_NONE },
{ .end = 1 },
{.hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_NONE},
{.end = 1},
};
//White
// White
led_setup_t leds_white[] = {
{ .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE },
{ .end = 1 },
{.hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE},
{.end = 1},
};
//White with moving red stripe
// White with moving red stripe
led_setup_t leds_white_with_red_stripe[] = {
{ .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE },
{ .hs = 0, .he = 15, .rs = 0, .re = 0, .gs = 0, .ge = 255, .bs = 0, .be = 255, .ef = EF_SCR_R | EF_SUBTRACT },
{ .hs = 15, .he = 30, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 0, .ef = EF_SCR_R | EF_SUBTRACT },
{ .end = 1 },
{.hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE},
{.hs = 0, .he = 15, .rs = 0, .re = 0, .gs = 0, .ge = 255, .bs = 0, .be = 255, .ef = EF_SCR_R | EF_SUBTRACT},
{.hs = 15, .he = 30, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 0, .ef = EF_SCR_R | EF_SUBTRACT},
{.end = 1},
};
//Black with moving red stripe
// Black with moving red stripe
led_setup_t leds_black_with_red_stripe[] = {
{ .hs = 0, .he = 15, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R },
{ .hs = 15, .he = 30, .rs = 255, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R },
{ .end = 1 },
{.hs = 0, .he = 15, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R},
{.hs = 15, .he = 30, .rs = 255, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R},
{.end = 1},
};
//Rainbow no scrolling
// Rainbow no scrolling
led_setup_t leds_rainbow_ns[] = {
{ .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER },
{ .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER },
{ .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER },
{ .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER },
{ .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER },
{ .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER },
{ .end = 1 },
{.hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER}, {.hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER}, {.hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER}, {.hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER}, {.hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER}, {.hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER}, {.end = 1},
};
//Rainbow scrolling
// Rainbow scrolling
led_setup_t leds_rainbow_s[] = {
{ .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R },
{ .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R },
{ .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER | EF_SCR_R },
{ .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R },
{ .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R },
{ .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER | EF_SCR_R },
{ .end = 1 },
{.hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R}, {.hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R}, {.hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER | EF_SCR_R}, {.hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R}, {.hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R}, {.hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER | EF_SCR_R}, {.end = 1},
};
//Add new LED animations here using one from above as example
//The last entry must be { .end = 1 }
//Add the new animation name to the list below following its format
// Add new LED animations here using one from above as example
// The last entry must be { .end = 1 }
// Add the new animation name to the list below following its format
void *led_setups[] = {
leds_rainbow_s,
leds_rainbow_ns,
leds_teal_salmon,
leds_yellow,
leds_red,
leds_green,
leds_blue,
leds_white,
leds_white_with_red_stripe,
leds_black_with_red_stripe,
leds_off
};
void *led_setups[] = {leds_rainbow_s, leds_rainbow_ns, leds_teal_salmon, leds_yellow, leds_red, leds_green, leds_blue, leds_white, leds_white_with_red_stripe, leds_black_with_red_stripe, leds_off};
const uint8_t led_setups_count = sizeof(led_setups) / sizeof(led_setups[0]);

View file

@ -25,50 +25,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <string.h>
#include "quantum.h"
//From protocol directory
// From protocol directory
#include "arm_atsam_protocol.h"
//From keyboard's directory
// From keyboard's directory
#include "config_led.h"
uint8_t g_usb_state = USB_FSMSTATUS_FSMSTATE_OFF_Val; //Saved USB state from hardware value to detect changes
uint8_t g_usb_state = USB_FSMSTATUS_FSMSTATE_OFF_Val; // Saved USB state from hardware value to detect changes
void main_subtasks(void);
void main_subtasks(void);
uint8_t keyboard_leds(void);
void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
void send_system(uint16_t data);
void send_consumer(uint16_t data);
void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
void send_system(uint16_t data);
void send_consumer(uint16_t data);
host_driver_t arm_atsam_driver = {
keyboard_leds,
send_keyboard,
send_mouse,
send_system,
send_consumer
};
host_driver_t arm_atsam_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
uint8_t led_states;
uint8_t keyboard_leds(void)
{
uint8_t keyboard_leds(void) {
#ifdef NKRO_ENABLE
if (keymap_config.nkro)
return udi_hid_nkro_report_set;
else
#endif //NKRO_ENABLE
#endif // NKRO_ENABLE
return udi_hid_kbd_report_set;
}
void send_keyboard(report_keyboard_t *report)
{
void send_keyboard(report_keyboard_t *report) {
uint32_t irqflags;
#ifdef NKRO_ENABLE
if (!keymap_config.nkro)
{
#endif //NKRO_ENABLE
while (udi_hid_kbd_b_report_trans_ongoing) { main_subtasks(); } //Run other tasks while waiting for USB to be free
if (!keymap_config.nkro) {
#endif // NKRO_ENABLE
while (udi_hid_kbd_b_report_trans_ongoing) {
main_subtasks();
} // Run other tasks while waiting for USB to be free
irqflags = __get_PRIMASK();
__disable_irq();
@ -81,10 +74,10 @@ void send_keyboard(report_keyboard_t *report)
__DMB();
__set_PRIMASK(irqflags);
#ifdef NKRO_ENABLE
}
else
{
while (udi_hid_nkro_b_report_trans_ongoing) { main_subtasks(); } //Run other tasks while waiting for USB to be free
} else {
while (udi_hid_nkro_b_report_trans_ongoing) {
main_subtasks();
} // Run other tasks while waiting for USB to be free
irqflags = __get_PRIMASK();
__disable_irq();
@ -97,11 +90,10 @@ void send_keyboard(report_keyboard_t *report)
__DMB();
__set_PRIMASK(irqflags);
}
#endif //NKRO_ENABLE
#endif // NKRO_ENABLE
}
void send_mouse(report_mouse_t *report)
{
void send_mouse(report_mouse_t *report) {
#ifdef MOUSEKEY_ENABLE
uint32_t irqflags;
@ -115,11 +107,10 @@ void send_mouse(report_mouse_t *report)
__DMB();
__set_PRIMASK(irqflags);
#endif //MOUSEKEY_ENABLE
#endif // MOUSEKEY_ENABLE
}
void send_system(uint16_t data)
{
void send_system(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
uint32_t irqflags;
@ -130,16 +121,15 @@ void send_system(uint16_t data)
udi_hid_exk_report.desc.report_id = REPORT_ID_SYSTEM;
if (data != 0) data = data - SYSTEM_POWER_DOWN + 1;
udi_hid_exk_report.desc.report_data = data;
udi_hid_exk_b_report_valid = 1;
udi_hid_exk_b_report_valid = 1;
udi_hid_exk_send_report();
__DMB();
__set_PRIMASK(irqflags);
#endif //EXTRAKEY_ENABLE
#endif // EXTRAKEY_ENABLE
}
void send_consumer(uint16_t data)
{
void send_consumer(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
uint32_t irqflags;
@ -147,71 +137,64 @@ void send_consumer(uint16_t data)
__disable_irq();
__DMB();
udi_hid_exk_report.desc.report_id = REPORT_ID_CONSUMER;
udi_hid_exk_report.desc.report_id = REPORT_ID_CONSUMER;
udi_hid_exk_report.desc.report_data = data;
udi_hid_exk_b_report_valid = 1;
udi_hid_exk_b_report_valid = 1;
udi_hid_exk_send_report();
__DMB();
__set_PRIMASK(irqflags);
#endif //EXTRAKEY_ENABLE
#endif // EXTRAKEY_ENABLE
}
void main_subtask_usb_state(void)
{
static uint64_t fsmstate_on_delay = 0; //Delay timer to be sure USB is actually operating before bringing up hardware
uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg; //Current state from hardware register
void main_subtask_usb_state(void) {
static uint64_t fsmstate_on_delay = 0; // Delay timer to be sure USB is actually operating before bringing up hardware
uint8_t fsmstate_now = USB->DEVICE.FSMSTATUS.reg; // Current state from hardware register
if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val) //If USB SUSPENDED
if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val) // If USB SUSPENDED
{
fsmstate_on_delay = 0; //Clear ON delay timer
fsmstate_on_delay = 0; // Clear ON delay timer
if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SUSPEND_Val) //If previously not SUSPENDED
if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SUSPEND_Val) // If previously not SUSPENDED
{
suspend_power_down(); //Run suspend routine
g_usb_state = fsmstate_now; //Save current USB state
suspend_power_down(); // Run suspend routine
g_usb_state = fsmstate_now; // Save current USB state
}
}
else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SLEEP_Val) //Else if USB SLEEPING
} else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_SLEEP_Val) // Else if USB SLEEPING
{
fsmstate_on_delay = 0; //Clear ON delay timer
fsmstate_on_delay = 0; // Clear ON delay timer
if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SLEEP_Val) //If previously not SLEEPING
if (g_usb_state != USB_FSMSTATUS_FSMSTATE_SLEEP_Val) // If previously not SLEEPING
{
suspend_power_down(); //Run suspend routine
g_usb_state = fsmstate_now; //Save current USB state
suspend_power_down(); // Run suspend routine
g_usb_state = fsmstate_now; // Save current USB state
}
}
else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_ON_Val) //Else if USB ON
} else if (fsmstate_now == USB_FSMSTATUS_FSMSTATE_ON_Val) // Else if USB ON
{
if (g_usb_state != USB_FSMSTATUS_FSMSTATE_ON_Val) //If previously not ON
if (g_usb_state != USB_FSMSTATUS_FSMSTATE_ON_Val) // If previously not ON
{
if (fsmstate_on_delay == 0) //If ON delay timer is cleared
if (fsmstate_on_delay == 0) // If ON delay timer is cleared
{
fsmstate_on_delay = timer_read64() + 250; //Set ON delay timer
}
else if (timer_read64() > fsmstate_on_delay) //Else if ON delay timer is active and timed out
fsmstate_on_delay = timer_read64() + 250; // Set ON delay timer
} else if (timer_read64() > fsmstate_on_delay) // Else if ON delay timer is active and timed out
{
suspend_wakeup_init(); //Run wakeup routine
g_usb_state = fsmstate_now; //Save current USB state
suspend_wakeup_init(); // Run wakeup routine
g_usb_state = fsmstate_now; // Save current USB state
}
}
}
else //Else if USB is in a state not being tracked
} else // Else if USB is in a state not being tracked
{
fsmstate_on_delay = 0; //Clear ON delay timer
fsmstate_on_delay = 0; // Clear ON delay timer
}
}
void main_subtask_power_check(void)
{
void main_subtask_power_check(void) {
static uint64_t next_5v_checkup = 0;
if (timer_read64() > next_5v_checkup)
{
if (timer_read64() > next_5v_checkup) {
next_5v_checkup = timer_read64() + 5;
v_5v = adc_get(ADC_5V);
v_5v = adc_get(ADC_5V);
v_5v_avg = 0.9 * v_5v_avg + 0.1 * v_5v;
#ifdef RGB_MATRIX_ENABLE
@ -220,27 +203,23 @@ void main_subtask_power_check(void)
}
}
void main_subtask_usb_extra_device(void)
{
void main_subtask_usb_extra_device(void) {
static uint64_t next_usb_checkup = 0;
if (timer_read64() > next_usb_checkup)
{
if (timer_read64() > next_usb_checkup) {
next_usb_checkup = timer_read64() + 10;
USB_HandleExtraDevice();
}
}
void main_subtasks(void)
{
void main_subtasks(void) {
main_subtask_usb_state();
main_subtask_power_check();
main_subtask_usb_extra_device();
}
int main(void)
{
int main(void) {
DBG_LED_ENA;
DBG_1_ENA;
DBG_1_OFF;
@ -259,7 +238,7 @@ int main(void)
#ifdef RGB_MATRIX_ENABLE
i2c1_init();
#endif // RGB_MATRIX_ENABLE
#endif // RGB_MATRIX_ENABLE
matrix_init();
@ -273,21 +252,23 @@ int main(void)
CDC_init();
DBGC(DC_MAIN_CDC_INIT_COMPLETE);
while (USB2422_Port_Detect_Init() == 0) {}
while (USB2422_Port_Detect_Init() == 0) {
}
DBG_LED_OFF;
#ifdef RGB_MATRIX_ENABLE
while (I2C3733_Init_Control() != 1) {}
while (I2C3733_Init_Drivers() != 1) {}
while (I2C3733_Init_Control() != 1) {
}
while (I2C3733_Init_Drivers() != 1) {
}
I2C_DMAC_LED_Init();
i2c_led_q_init();
for (uint8_t drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++)
I2C_LED_Q_ONOFF(drvid); //Queue data
#endif // RGB_MATRIX_ENABLE
for (uint8_t drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++) I2C_LED_Q_ONOFF(drvid); // Queue data
#endif // RGB_MATRIX_ENABLE
keyboard_setup();
@ -297,21 +278,18 @@ int main(void)
#ifdef CONSOLE_ENABLE
uint64_t next_print = 0;
#endif //CONSOLE_ENABLE
#endif // CONSOLE_ENABLE
v_5v_avg = adc_get(ADC_5V);
debug_code_disable();
while (1)
{
main_subtasks(); //Note these tasks will also be run while waiting for USB keyboard polling intervals
while (1) {
main_subtasks(); // Note these tasks will also be run while waiting for USB keyboard polling intervals
if (g_usb_state == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val || g_usb_state == USB_FSMSTATUS_FSMSTATE_SLEEP_Val)
{
if (suspend_wakeup_condition())
{
udc_remotewakeup(); //Send remote wakeup signal
if (g_usb_state == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val || g_usb_state == USB_FSMSTATUS_FSMSTATE_SLEEP_Val) {
if (suspend_wakeup_condition()) {
udc_remotewakeup(); // Send remote wakeup signal
wait_ms(50);
}
@ -321,16 +299,13 @@ int main(void)
keyboard_task();
#ifdef CONSOLE_ENABLE
if (timer_read64() > next_print)
{
if (timer_read64() > next_print) {
next_print = timer_read64() + 250;
//Add any debug information here that you want to see very often
//dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired);
// Add any debug information here that you want to see very often
// dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired);
}
#endif //CONSOLE_ENABLE
#endif // CONSOLE_ENABLE
}
return 1;
}

View file

@ -20,4 +20,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
uint8_t keyboard_leds(void);
#endif //_MAIN_ARM_ATSAM_H_
#endif //_MAIN_ARM_ATSAM_H_

View file

@ -5,20 +5,20 @@ extern uint32_t _srom;
extern uint32_t _lrom;
extern uint32_t _erom;
#define BOOTLOADER_SERIAL_MAX_SIZE 20 //DO NOT MODIFY!
#define BOOTLOADER_SERIAL_MAX_SIZE 20 // DO NOT MODIFY!
#ifdef KEYBOARD_massdrop_ctrl
//WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support
// WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support
extern uint32_t _eram;
#define BOOTLOADER_MAGIC 0x3B9ACA00
#define MAGIC_ADDR (uint32_t *)((intptr_t)(&_eram) - 4)
# define BOOTLOADER_MAGIC 0x3B9ACA00
# define MAGIC_ADDR (uint32_t *)((intptr_t)(&_eram) - 4)
#endif
#ifdef MD_BOOTLOADER
#define MCU_HZ 48000000
#define I2C_HZ 0 //Not used
# define MCU_HZ 48000000
# define I2C_HZ 0 // Not used
#endif //MD_BOOTLOADER
#endif // MD_BOOTLOADER
#endif //_MD_BOOTLOADER_H_
#endif //_MD_BOOTLOADER_H_

View file

@ -19,69 +19,74 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
sr_exp_t sr_exp_data;
void SR_EXP_WriteData(void)
{
void SR_EXP_WriteData(void) {
SR_EXP_RCLK_LO;
while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.DRE)) { DBGC(DC_SPI_WRITE_DRE); }
while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.DRE)) {
DBGC(DC_SPI_WRITE_DRE);
}
SR_EXP_SERCOM->SPI.DATA.bit.DATA = sr_exp_data.reg & 0xFF; //Shift in bits 7-0
while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.TXC)) { DBGC(DC_SPI_WRITE_TXC_1); }
SR_EXP_SERCOM->SPI.DATA.bit.DATA = sr_exp_data.reg & 0xFF; // Shift in bits 7-0
while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.TXC)) {
DBGC(DC_SPI_WRITE_TXC_1);
}
SR_EXP_SERCOM->SPI.DATA.bit.DATA = (sr_exp_data.reg >> 8) & 0xFF; //Shift in bits 15-8
while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.TXC)) { DBGC(DC_SPI_WRITE_TXC_2); }
SR_EXP_SERCOM->SPI.DATA.bit.DATA = (sr_exp_data.reg >> 8) & 0xFF; // Shift in bits 15-8
while (!(SR_EXP_SERCOM->SPI.INTFLAG.bit.TXC)) {
DBGC(DC_SPI_WRITE_TXC_2);
}
SR_EXP_RCLK_HI;
}
void SR_EXP_Init(void)
{
void SR_EXP_Init(void) {
DBGC(DC_SPI_INIT_BEGIN);
CLK_set_spi_freq(CHAN_SERCOM_SPI, FREQ_SPI_DEFAULT);
//Set up MCU Shift Register pins
// Set up MCU Shift Register pins
PORT->Group[SR_EXP_RCLK_PORT].DIRSET.reg = (1 << SR_EXP_RCLK_PIN);
PORT->Group[SR_EXP_OE_N_PORT].DIRSET.reg = (1 << SR_EXP_OE_N_PIN);
//Set up MCU SPI pins
PORT->Group[SR_EXP_DATAOUT_PORT].PMUX[SR_EXP_DATAOUT_PIN / 2].bit.SR_EXP_DATAOUT_MUX_SEL = SR_EXP_DATAOUT_MUX; //MUX select for sercom
PORT->Group[SR_EXP_SCLK_PORT].PMUX[SR_EXP_SCLK_PIN / 2].bit.SR_EXP_SCLK_MUX_SEL = SR_EXP_SCLK_MUX; //MUX select for sercom
PORT->Group[SR_EXP_DATAOUT_PORT].PINCFG[SR_EXP_DATAOUT_PIN].bit.PMUXEN = 1; //MUX Enable
PORT->Group[SR_EXP_SCLK_PORT].PINCFG[SR_EXP_SCLK_PIN].bit.PMUXEN = 1; //MUX Enable
//Initialize Shift Register
// Set up MCU SPI pins
PORT->Group[SR_EXP_DATAOUT_PORT].PMUX[SR_EXP_DATAOUT_PIN / 2].bit.SR_EXP_DATAOUT_MUX_SEL = SR_EXP_DATAOUT_MUX; // MUX select for sercom
PORT->Group[SR_EXP_SCLK_PORT].PMUX[SR_EXP_SCLK_PIN / 2].bit.SR_EXP_SCLK_MUX_SEL = SR_EXP_SCLK_MUX; // MUX select for sercom
PORT->Group[SR_EXP_DATAOUT_PORT].PINCFG[SR_EXP_DATAOUT_PIN].bit.PMUXEN = 1; // MUX Enable
PORT->Group[SR_EXP_SCLK_PORT].PINCFG[SR_EXP_SCLK_PIN].bit.PMUXEN = 1; // MUX Enable
// Initialize Shift Register
SR_EXP_OE_N_DIS;
SR_EXP_RCLK_HI;
SR_EXP_SERCOM->SPI.CTRLA.bit.DORD = 1; //Data Order - LSB is transferred first
SR_EXP_SERCOM->SPI.CTRLA.bit.CPOL = 1; //Clock Polarity - SCK high when idle. Leading edge of cycle is falling. Trailing rising.
SR_EXP_SERCOM->SPI.CTRLA.bit.CPHA = 1; //Clock Phase - Leading Edge Falling, change, Trailing Edge - Rising, sample
SR_EXP_SERCOM->SPI.CTRLA.bit.DIPO = 3; //Data In Pinout - SERCOM PAD[3] is used as data input (Configure away from DOPO. Not using input.)
SR_EXP_SERCOM->SPI.CTRLA.bit.DOPO = 0; //Data Output PAD[0], Serial Clock PAD[1]
SR_EXP_SERCOM->SPI.CTRLA.bit.MODE = 3; //Operating Mode - Master operation
SR_EXP_SERCOM->SPI.CTRLA.bit.DORD = 1; // Data Order - LSB is transferred first
SR_EXP_SERCOM->SPI.CTRLA.bit.CPOL = 1; // Clock Polarity - SCK high when idle. Leading edge of cycle is falling. Trailing rising.
SR_EXP_SERCOM->SPI.CTRLA.bit.CPHA = 1; // Clock Phase - Leading Edge Falling, change, Trailing Edge - Rising, sample
SR_EXP_SERCOM->SPI.CTRLA.bit.DIPO = 3; // Data In Pinout - SERCOM PAD[3] is used as data input (Configure away from DOPO. Not using input.)
SR_EXP_SERCOM->SPI.CTRLA.bit.DOPO = 0; // Data Output PAD[0], Serial Clock PAD[1]
SR_EXP_SERCOM->SPI.CTRLA.bit.MODE = 3; // Operating Mode - Master operation
SR_EXP_SERCOM->SPI.CTRLA.bit.ENABLE = 1; //Enable - Peripheral is enabled or being enabled
while (SR_EXP_SERCOM->SPI.SYNCBUSY.bit.ENABLE) { DBGC(DC_SPI_SYNC_ENABLING); }
SR_EXP_SERCOM->SPI.CTRLA.bit.ENABLE = 1; // Enable - Peripheral is enabled or being enabled
while (SR_EXP_SERCOM->SPI.SYNCBUSY.bit.ENABLE) {
DBGC(DC_SPI_SYNC_ENABLING);
}
sr_exp_data.reg = 0;
sr_exp_data.reg = 0;
sr_exp_data.bit.HUB_CONNECT = 0;
sr_exp_data.bit.HUB_RESET_N = 0;
sr_exp_data.bit.S_UP = 0;
sr_exp_data.bit.E_UP_N = 1;
sr_exp_data.bit.S_DN1 = 1;
sr_exp_data.bit.E_DN1_N = 1;
sr_exp_data.bit.E_VBUS_1 = 0;
sr_exp_data.bit.E_VBUS_2 = 0;
sr_exp_data.bit.SRC_1 = 1;
sr_exp_data.bit.SRC_2 = 1;
sr_exp_data.bit.IRST = 1;
sr_exp_data.bit.SDB_N = 0;
sr_exp_data.bit.S_UP = 0;
sr_exp_data.bit.E_UP_N = 1;
sr_exp_data.bit.S_DN1 = 1;
sr_exp_data.bit.E_DN1_N = 1;
sr_exp_data.bit.E_VBUS_1 = 0;
sr_exp_data.bit.E_VBUS_2 = 0;
sr_exp_data.bit.SRC_1 = 1;
sr_exp_data.bit.SRC_2 = 1;
sr_exp_data.bit.IRST = 1;
sr_exp_data.bit.SDB_N = 0;
SR_EXP_WriteData();
//Enable Shift Register output
// Enable Shift Register output
SR_EXP_OE_N_ENA;
DBGC(DC_SPI_INIT_COMPLETE);
}

View file

@ -26,40 +26,40 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Determine bits to set for mux selection */
#if SR_EXP_DATAOUT_PIN % 2 == 0
#define SR_EXP_DATAOUT_MUX_SEL PMUXE
# define SR_EXP_DATAOUT_MUX_SEL PMUXE
#else
#define SR_EXP_DATAOUT_MUX_SEL PMUXO
# define SR_EXP_DATAOUT_MUX_SEL PMUXO
#endif
/* Determine bits to set for mux selection */
#if SR_EXP_SCLK_PIN % 2 == 0
#define SR_EXP_SCLK_MUX_SEL PMUXE
# define SR_EXP_SCLK_MUX_SEL PMUXE
#else
#define SR_EXP_SCLK_MUX_SEL PMUXO
# define SR_EXP_SCLK_MUX_SEL PMUXO
#endif
/* Data structure to define Shift Register output expander hardware */
/* This structure gets shifted into registers LSB first */
typedef union {
struct {
uint16_t RSVD4:1; /*!< bit: 0 */
uint16_t RSVD3:1; /*!< bit: 1 */
uint16_t RSVD2:1; /*!< bit: 2 */
uint16_t RSVD1:1; /*!< bit: 3 */
uint16_t SDB_N:1; /*!< bit: 4 SHUTDOWN THE CHIP WHEN 0, RUN WHEN 1 */
uint16_t IRST:1; /*!< bit: 5 RESET THE IS3733 I2C WHEN 1, RUN WHEN 0 */
uint16_t SRC_2:1; /*!< bit: 6 ADVERTISE A SOURCE TO USBC-2 CC */
uint16_t SRC_1:1; /*!< bit: 7 ADVERTISE A SOURCE TO USBC-1 CC */
uint16_t E_VBUS_2:1; /*!< bit: 8 ENABLE 5V OUT TO USBC-2 WHEN 1 */
uint16_t E_VBUS_1:1; /*!< bit: 9 ENABLE 5V OUT TO USBC-1 WHEN 1 */
uint16_t E_DN1_N:1; /*!< bit: 10 ENABLE DN1 1:2 MUX WHEN 0 */
uint16_t S_DN1:1; /*!< bit: 11 SELECT DN1 PATH 0:USBC-1, 1:USBC-2 */
uint16_t E_UP_N:1; /*!< bit: 12 ENABLE SUP 1:2 MUX WHEN 0 */
uint16_t S_UP:1; /*!< bit: 13 SELECT UP PATH 0:USBC-1, 1:USBC-2 */
uint16_t HUB_RESET_N:1; /*!< bit: 14 RESET USB HUB WHEN 0, RUN WHEN 1 */
uint16_t HUB_CONNECT:1; /*!< bit: 15 SIGNAL VBUS CONNECT TO USB HUB WHEN 1 */
} bit; /*!< Structure used for bit access */
uint16_t reg; /*!< Type used for register access */
struct {
uint16_t RSVD4 : 1; /*!< bit: 0 */
uint16_t RSVD3 : 1; /*!< bit: 1 */
uint16_t RSVD2 : 1; /*!< bit: 2 */
uint16_t RSVD1 : 1; /*!< bit: 3 */
uint16_t SDB_N : 1; /*!< bit: 4 SHUTDOWN THE CHIP WHEN 0, RUN WHEN 1 */
uint16_t IRST : 1; /*!< bit: 5 RESET THE IS3733 I2C WHEN 1, RUN WHEN 0 */
uint16_t SRC_2 : 1; /*!< bit: 6 ADVERTISE A SOURCE TO USBC-2 CC */
uint16_t SRC_1 : 1; /*!< bit: 7 ADVERTISE A SOURCE TO USBC-1 CC */
uint16_t E_VBUS_2 : 1; /*!< bit: 8 ENABLE 5V OUT TO USBC-2 WHEN 1 */
uint16_t E_VBUS_1 : 1; /*!< bit: 9 ENABLE 5V OUT TO USBC-1 WHEN 1 */
uint16_t E_DN1_N : 1; /*!< bit: 10 ENABLE DN1 1:2 MUX WHEN 0 */
uint16_t S_DN1 : 1; /*!< bit: 11 SELECT DN1 PATH 0:USBC-1, 1:USBC-2 */
uint16_t E_UP_N : 1; /*!< bit: 12 ENABLE SUP 1:2 MUX WHEN 0 */
uint16_t S_UP : 1; /*!< bit: 13 SELECT UP PATH 0:USBC-1, 1:USBC-2 */
uint16_t HUB_RESET_N : 1; /*!< bit: 14 RESET USB HUB WHEN 0, RUN WHEN 1 */
uint16_t HUB_CONNECT : 1; /*!< bit: 15 SIGNAL VBUS CONNECT TO USB HUB WHEN 1 */
} bit; /*!< Structure used for bit access */
uint16_t reg; /*!< Type used for register access */
} sr_exp_t;
extern sr_exp_t sr_exp_data;
@ -67,4 +67,4 @@ extern sr_exp_t sr_exp_data;
void SR_EXP_WriteData(void);
void SR_EXP_Init(void);
#endif //_SPI_H_
#endif //_SPI_H_

View file

@ -14,9 +14,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the Licence at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -51,447 +51,448 @@ void __libc_init_array(void);
void Dummy_Handler(void);
/* Cortex-M4 core handlers */
void NMI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void HardFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void MemManage_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void BusFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void UsageFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void SVC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void DebugMon_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void PendSV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void SysTick_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void NMI_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void HardFault_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void MemManage_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void BusFault_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void UsageFault_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void SVC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void DebugMon_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void PendSV_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void SysTick_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
/* Peripherals handlers */
void PM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void MCLK_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void OSCCTRL_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_XOSCFAIL_0, OSCCTRL_XOSCRDY_0 */
void OSCCTRL_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_XOSCFAIL_1, OSCCTRL_XOSCRDY_1 */
void OSCCTRL_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_DFLLLOCKC, OSCCTRL_DFLLLOCKF, OSCCTRL_DFLLOOB, OSCCTRL_DFLLRCS, OSCCTRL_DFLLRDY */
void OSCCTRL_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_DPLLLCKF_0, OSCCTRL_DPLLLCKR_0, OSCCTRL_DPLLLDRTO_0, OSCCTRL_DPLLLTO_0 */
void OSCCTRL_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* OSCCTRL_DPLLLCKF_1, OSCCTRL_DPLLLCKR_1, OSCCTRL_DPLLLDRTO_1, OSCCTRL_DPLLLTO_1 */
void OSC32KCTRL_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void SUPC_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SUPC_B12SRDY, SUPC_B33SRDY, SUPC_BOD12RDY, SUPC_BOD33RDY, SUPC_VCORERDY, SUPC_VREGRDY */
void SUPC_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SUPC_BOD12DET, SUPC_BOD33DET */
void WDT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void RTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void EIC_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_0 */
void EIC_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_1 */
void EIC_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_2 */
void EIC_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_3 */
void EIC_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_4 */
void EIC_5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_5 */
void EIC_6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_6 */
void EIC_7_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_7 */
void EIC_8_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_8 */
void EIC_9_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_9 */
void EIC_10_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_10 */
void EIC_11_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_11 */
void EIC_12_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_12 */
void EIC_13_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_13 */
void EIC_14_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_14 */
void EIC_15_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_15 */
void FREQM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void NVMCTRL_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* NVMCTRL_0, NVMCTRL_1, NVMCTRL_2, NVMCTRL_3, NVMCTRL_4, NVMCTRL_5, NVMCTRL_6, NVMCTRL_7 */
void NVMCTRL_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* NVMCTRL_10, NVMCTRL_8, NVMCTRL_9 */
void DMAC_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_0, DMAC_TCMPL_0, DMAC_TERR_0 */
void DMAC_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_1, DMAC_TCMPL_1, DMAC_TERR_1 */
void DMAC_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_2, DMAC_TCMPL_2, DMAC_TERR_2 */
void DMAC_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_3, DMAC_TCMPL_3, DMAC_TERR_3 */
void DMAC_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_10, DMAC_SUSP_11, DMAC_SUSP_12, DMAC_SUSP_13, DMAC_SUSP_14, DMAC_SUSP_15, DMAC_SUSP_16, DMAC_SUSP_17, DMAC_SUSP_18, DMAC_SUSP_19, DMAC_SUSP_20, DMAC_SUSP_21, DMAC_SUSP_22, DMAC_SUSP_23, DMAC_SUSP_24, DMAC_SUSP_25, DMAC_SUSP_26, DMAC_SUSP_27, DMAC_SUSP_28, DMAC_SUSP_29, DMAC_SUSP_30, DMAC_SUSP_31, DMAC_SUSP_4, DMAC_SUSP_5, DMAC_SUSP_6, DMAC_SUSP_7, DMAC_SUSP_8, DMAC_SUSP_9, DMAC_TCMPL_10, DMAC_TCMPL_11, DMAC_TCMPL_12, DMAC_TCMPL_13, DMAC_TCMPL_14, DMAC_TCMPL_15, DMAC_TCMPL_16, DMAC_TCMPL_17, DMAC_TCMPL_18, DMAC_TCMPL_19, DMAC_TCMPL_20, DMAC_TCMPL_21, DMAC_TCMPL_22, DMAC_TCMPL_23, DMAC_TCMPL_24, DMAC_TCMPL_25, DMAC_TCMPL_26, DMAC_TCMPL_27, DMAC_TCMPL_28, DMAC_TCMPL_29, DMAC_TCMPL_30, DMAC_TCMPL_31, DMAC_TCMPL_4, DMAC_TCMPL_5, DMAC_TCMPL_6, DMAC_TCMPL_7, DMAC_TCMPL_8, DMAC_TCMPL_9, DMAC_TERR_10, DMAC_TERR_11, DMAC_TERR_12, DMAC_TERR_13, DMAC_TERR_14, DMAC_TERR_15, DMAC_TERR_16, DMAC_TERR_17, DMAC_TERR_18, DMAC_TERR_19, DMAC_TERR_20, DMAC_TERR_21, DMAC_TERR_22, DMAC_TERR_23, DMAC_TERR_24, DMAC_TERR_25, DMAC_TERR_26, DMAC_TERR_27, DMAC_TERR_28, DMAC_TERR_29, DMAC_TERR_30, DMAC_TERR_31, DMAC_TERR_4, DMAC_TERR_5, DMAC_TERR_6, DMAC_TERR_7, DMAC_TERR_8, DMAC_TERR_9 */
void EVSYS_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_0, EVSYS_OVR_0 */
void EVSYS_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_1, EVSYS_OVR_1 */
void EVSYS_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_2, EVSYS_OVR_2 */
void EVSYS_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_3, EVSYS_OVR_3 */
void EVSYS_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_10, EVSYS_EVD_11, EVSYS_EVD_4, EVSYS_EVD_5, EVSYS_EVD_6, EVSYS_EVD_7, EVSYS_EVD_8, EVSYS_EVD_9, EVSYS_OVR_10, EVSYS_OVR_11, EVSYS_OVR_4, EVSYS_OVR_5, EVSYS_OVR_6, EVSYS_OVR_7, EVSYS_OVR_8, EVSYS_OVR_9 */
void PAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TAL_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TAL_BRK */
void TAL_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TAL_IPS_0, TAL_IPS_1 */
void RAMECC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void SERCOM0_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM0_0 */
void SERCOM0_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM0_1 */
void SERCOM0_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM0_2 */
void SERCOM0_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM0_3, SERCOM0_4, SERCOM0_5, SERCOM0_6 */
void SERCOM1_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM1_0 */
void SERCOM1_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM1_1 */
void SERCOM1_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM1_2 */
void SERCOM1_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM1_3, SERCOM1_4, SERCOM1_5, SERCOM1_6 */
void SERCOM2_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM2_0 */
void SERCOM2_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM2_1 */
void SERCOM2_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM2_2 */
void SERCOM2_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM2_3, SERCOM2_4, SERCOM2_5, SERCOM2_6 */
void SERCOM3_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM3_0 */
void SERCOM3_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM3_1 */
void SERCOM3_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM3_2 */
void SERCOM3_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM3_3, SERCOM3_4, SERCOM3_5, SERCOM3_6 */
void PM_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void MCLK_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void OSCCTRL_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_XOSCFAIL_0, OSCCTRL_XOSCRDY_0 */
void OSCCTRL_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_XOSCFAIL_1, OSCCTRL_XOSCRDY_1 */
void OSCCTRL_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_DFLLLOCKC, OSCCTRL_DFLLLOCKF, OSCCTRL_DFLLOOB, OSCCTRL_DFLLRCS, OSCCTRL_DFLLRDY */
void OSCCTRL_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_DPLLLCKF_0, OSCCTRL_DPLLLCKR_0, OSCCTRL_DPLLLDRTO_0, OSCCTRL_DPLLLTO_0 */
void OSCCTRL_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* OSCCTRL_DPLLLCKF_1, OSCCTRL_DPLLLCKR_1, OSCCTRL_DPLLLDRTO_1, OSCCTRL_DPLLLTO_1 */
void OSC32KCTRL_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void SUPC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SUPC_B12SRDY, SUPC_B33SRDY, SUPC_BOD12RDY, SUPC_BOD33RDY, SUPC_VCORERDY, SUPC_VREGRDY */
void SUPC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SUPC_BOD12DET, SUPC_BOD33DET */
void WDT_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void RTC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void EIC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_0 */
void EIC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_1 */
void EIC_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_2 */
void EIC_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_3 */
void EIC_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_4 */
void EIC_5_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_5 */
void EIC_6_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_6 */
void EIC_7_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_7 */
void EIC_8_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_8 */
void EIC_9_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_9 */
void EIC_10_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_10 */
void EIC_11_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_11 */
void EIC_12_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_12 */
void EIC_13_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_13 */
void EIC_14_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_14 */
void EIC_15_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EIC_EXTINT_15 */
void FREQM_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void NVMCTRL_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* NVMCTRL_0, NVMCTRL_1, NVMCTRL_2, NVMCTRL_3, NVMCTRL_4, NVMCTRL_5, NVMCTRL_6, NVMCTRL_7 */
void NVMCTRL_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* NVMCTRL_10, NVMCTRL_8, NVMCTRL_9 */
void DMAC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_0, DMAC_TCMPL_0, DMAC_TERR_0 */
void DMAC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_1, DMAC_TCMPL_1, DMAC_TERR_1 */
void DMAC_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_2, DMAC_TCMPL_2, DMAC_TERR_2 */
void DMAC_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_3, DMAC_TCMPL_3, DMAC_TERR_3 */
void DMAC_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DMAC_SUSP_10, DMAC_SUSP_11, DMAC_SUSP_12, DMAC_SUSP_13, DMAC_SUSP_14, DMAC_SUSP_15, DMAC_SUSP_16, DMAC_SUSP_17, DMAC_SUSP_18, DMAC_SUSP_19, DMAC_SUSP_20, DMAC_SUSP_21, DMAC_SUSP_22, DMAC_SUSP_23, DMAC_SUSP_24, DMAC_SUSP_25, DMAC_SUSP_26, DMAC_SUSP_27, DMAC_SUSP_28, DMAC_SUSP_29, DMAC_SUSP_30, DMAC_SUSP_31, DMAC_SUSP_4, DMAC_SUSP_5, DMAC_SUSP_6, DMAC_SUSP_7, DMAC_SUSP_8, DMAC_SUSP_9, DMAC_TCMPL_10, DMAC_TCMPL_11, DMAC_TCMPL_12, DMAC_TCMPL_13, DMAC_TCMPL_14, DMAC_TCMPL_15, DMAC_TCMPL_16, DMAC_TCMPL_17, DMAC_TCMPL_18, DMAC_TCMPL_19, DMAC_TCMPL_20, DMAC_TCMPL_21, DMAC_TCMPL_22, DMAC_TCMPL_23, DMAC_TCMPL_24, DMAC_TCMPL_25, DMAC_TCMPL_26, DMAC_TCMPL_27, DMAC_TCMPL_28, DMAC_TCMPL_29, DMAC_TCMPL_30, DMAC_TCMPL_31, DMAC_TCMPL_4, DMAC_TCMPL_5, DMAC_TCMPL_6, DMAC_TCMPL_7, DMAC_TCMPL_8, DMAC_TCMPL_9, DMAC_TERR_10, DMAC_TERR_11, DMAC_TERR_12, DMAC_TERR_13, DMAC_TERR_14, DMAC_TERR_15, DMAC_TERR_16, DMAC_TERR_17,
DMAC_TERR_18, DMAC_TERR_19, DMAC_TERR_20, DMAC_TERR_21, DMAC_TERR_22, DMAC_TERR_23, DMAC_TERR_24, DMAC_TERR_25, DMAC_TERR_26, DMAC_TERR_27, DMAC_TERR_28, DMAC_TERR_29, DMAC_TERR_30, DMAC_TERR_31, DMAC_TERR_4, DMAC_TERR_5, DMAC_TERR_6, DMAC_TERR_7, DMAC_TERR_8, DMAC_TERR_9 */
void EVSYS_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_0, EVSYS_OVR_0 */
void EVSYS_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_1, EVSYS_OVR_1 */
void EVSYS_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_2, EVSYS_OVR_2 */
void EVSYS_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_3, EVSYS_OVR_3 */
void EVSYS_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* EVSYS_EVD_10, EVSYS_EVD_11, EVSYS_EVD_4, EVSYS_EVD_5, EVSYS_EVD_6, EVSYS_EVD_7, EVSYS_EVD_8, EVSYS_EVD_9, EVSYS_OVR_10, EVSYS_OVR_11, EVSYS_OVR_4, EVSYS_OVR_5, EVSYS_OVR_6, EVSYS_OVR_7, EVSYS_OVR_8, EVSYS_OVR_9 */
void PAC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void TAL_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TAL_BRK */
void TAL_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TAL_IPS_0, TAL_IPS_1 */
void RAMECC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void SERCOM0_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM0_0 */
void SERCOM0_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM0_1 */
void SERCOM0_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM0_2 */
void SERCOM0_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM0_3, SERCOM0_4, SERCOM0_5, SERCOM0_6 */
void SERCOM1_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM1_0 */
void SERCOM1_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM1_1 */
void SERCOM1_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM1_2 */
void SERCOM1_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM1_3, SERCOM1_4, SERCOM1_5, SERCOM1_6 */
void SERCOM2_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM2_0 */
void SERCOM2_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM2_1 */
void SERCOM2_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM2_2 */
void SERCOM2_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM2_3, SERCOM2_4, SERCOM2_5, SERCOM2_6 */
void SERCOM3_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM3_0 */
void SERCOM3_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM3_1 */
void SERCOM3_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM3_2 */
void SERCOM3_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM3_3, SERCOM3_4, SERCOM3_5, SERCOM3_6 */
#ifdef ID_SERCOM4
void SERCOM4_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM4_0 */
void SERCOM4_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM4_1 */
void SERCOM4_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM4_2 */
void SERCOM4_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM4_3, SERCOM4_4, SERCOM4_5, SERCOM4_6 */
void SERCOM4_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM4_0 */
void SERCOM4_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM4_1 */
void SERCOM4_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM4_2 */
void SERCOM4_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM4_3, SERCOM4_4, SERCOM4_5, SERCOM4_6 */
#endif
#ifdef ID_SERCOM5
void SERCOM5_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM5_0 */
void SERCOM5_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM5_1 */
void SERCOM5_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM5_2 */
void SERCOM5_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM5_3, SERCOM5_4, SERCOM5_5, SERCOM5_6 */
void SERCOM5_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM5_0 */
void SERCOM5_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM5_1 */
void SERCOM5_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM5_2 */
void SERCOM5_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM5_3, SERCOM5_4, SERCOM5_5, SERCOM5_6 */
#endif
#ifdef ID_SERCOM6
void SERCOM6_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM6_0 */
void SERCOM6_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM6_1 */
void SERCOM6_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM6_2 */
void SERCOM6_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM6_3, SERCOM6_4, SERCOM6_5, SERCOM6_6 */
void SERCOM6_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM6_0 */
void SERCOM6_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM6_1 */
void SERCOM6_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM6_2 */
void SERCOM6_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM6_3, SERCOM6_4, SERCOM6_5, SERCOM6_6 */
#endif
#ifdef ID_SERCOM7
void SERCOM7_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM7_0 */
void SERCOM7_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM7_1 */
void SERCOM7_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM7_2 */
void SERCOM7_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* SERCOM7_3, SERCOM7_4, SERCOM7_5, SERCOM7_6 */
void SERCOM7_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM7_0 */
void SERCOM7_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM7_1 */
void SERCOM7_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM7_2 */
void SERCOM7_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* SERCOM7_3, SERCOM7_4, SERCOM7_5, SERCOM7_6 */
#endif
#ifdef ID_CAN0
void CAN0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void CAN0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
#ifdef ID_CAN1
void CAN1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void CAN1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
#ifdef ID_USB
void USB_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN, USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1, USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4, USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7, USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2, USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5, USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1, USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6, USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1, USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4, USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7, USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2, USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5, USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
void USB_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* USB_SOF_HSOF */
void USB_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2, USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5, USB_TRCPT0_6, USB_TRCPT0_7 */
void USB_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2, USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5, USB_TRCPT1_6, USB_TRCPT1_7 */
void USB_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN, USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1, USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4, USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7, USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2, USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5, USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1, USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6, USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1, USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4, USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7, USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2, USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5, USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
void USB_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* USB_SOF_HSOF */
void USB_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2, USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5, USB_TRCPT0_6, USB_TRCPT0_7 */
void USB_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2, USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5, USB_TRCPT1_6, USB_TRCPT1_7 */
#endif
#ifdef ID_GMAC
void GMAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void GMAC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
void TCC0_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_CNT_A, TCC0_DFS_A, TCC0_ERR_A, TCC0_FAULT0_A, TCC0_FAULT1_A, TCC0_FAULTA_A, TCC0_FAULTB_A, TCC0_OVF, TCC0_TRG, TCC0_UFS_A */
void TCC0_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_0 */
void TCC0_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_1 */
void TCC0_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_2 */
void TCC0_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_3 */
void TCC0_5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_4 */
void TCC0_6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC0_MC_5 */
void TCC1_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_CNT_A, TCC1_DFS_A, TCC1_ERR_A, TCC1_FAULT0_A, TCC1_FAULT1_A, TCC1_FAULTA_A, TCC1_FAULTB_A, TCC1_OVF, TCC1_TRG, TCC1_UFS_A */
void TCC1_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_MC_0 */
void TCC1_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_MC_1 */
void TCC1_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_MC_2 */
void TCC1_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC1_MC_3 */
void TCC2_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC2_CNT_A, TCC2_DFS_A, TCC2_ERR_A, TCC2_FAULT0_A, TCC2_FAULT1_A, TCC2_FAULTA_A, TCC2_FAULTB_A, TCC2_OVF, TCC2_TRG, TCC2_UFS_A */
void TCC2_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC2_MC_0 */
void TCC2_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC2_MC_1 */
void TCC2_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC2_MC_2 */
void TCC0_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_CNT_A, TCC0_DFS_A, TCC0_ERR_A, TCC0_FAULT0_A, TCC0_FAULT1_A, TCC0_FAULTA_A, TCC0_FAULTB_A, TCC0_OVF, TCC0_TRG, TCC0_UFS_A */
void TCC0_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_0 */
void TCC0_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_1 */
void TCC0_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_2 */
void TCC0_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_3 */
void TCC0_5_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_4 */
void TCC0_6_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC0_MC_5 */
void TCC1_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_CNT_A, TCC1_DFS_A, TCC1_ERR_A, TCC1_FAULT0_A, TCC1_FAULT1_A, TCC1_FAULTA_A, TCC1_FAULTB_A, TCC1_OVF, TCC1_TRG, TCC1_UFS_A */
void TCC1_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_MC_0 */
void TCC1_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_MC_1 */
void TCC1_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_MC_2 */
void TCC1_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC1_MC_3 */
void TCC2_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC2_CNT_A, TCC2_DFS_A, TCC2_ERR_A, TCC2_FAULT0_A, TCC2_FAULT1_A, TCC2_FAULTA_A, TCC2_FAULTB_A, TCC2_OVF, TCC2_TRG, TCC2_UFS_A */
void TCC2_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC2_MC_0 */
void TCC2_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC2_MC_1 */
void TCC2_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC2_MC_2 */
#ifdef ID_TCC3
void TCC3_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC3_CNT_A, TCC3_DFS_A, TCC3_ERR_A, TCC3_FAULT0_A, TCC3_FAULT1_A, TCC3_FAULTA_A, TCC3_FAULTB_A, TCC3_OVF, TCC3_TRG, TCC3_UFS_A */
void TCC3_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC3_MC_0 */
void TCC3_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC3_MC_1 */
void TCC3_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC3_CNT_A, TCC3_DFS_A, TCC3_ERR_A, TCC3_FAULT0_A, TCC3_FAULT1_A, TCC3_FAULTA_A, TCC3_FAULTB_A, TCC3_OVF, TCC3_TRG, TCC3_UFS_A */
void TCC3_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC3_MC_0 */
void TCC3_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC3_MC_1 */
#endif
#ifdef ID_TCC4
void TCC4_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC4_CNT_A, TCC4_DFS_A, TCC4_ERR_A, TCC4_FAULT0_A, TCC4_FAULT1_A, TCC4_FAULTA_A, TCC4_FAULTB_A, TCC4_OVF, TCC4_TRG, TCC4_UFS_A */
void TCC4_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC4_MC_0 */
void TCC4_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* TCC4_MC_1 */
void TCC4_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC4_CNT_A, TCC4_DFS_A, TCC4_ERR_A, TCC4_FAULT0_A, TCC4_FAULT1_A, TCC4_FAULTA_A, TCC4_FAULTB_A, TCC4_OVF, TCC4_TRG, TCC4_UFS_A */
void TCC4_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC4_MC_0 */
void TCC4_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* TCC4_MC_1 */
#endif
void TC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TC2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TC3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TC0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void TC1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void TC2_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void TC3_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#ifdef ID_TC4
void TC4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TC4_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
#ifdef ID_TC5
void TC5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TC5_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
#ifdef ID_TC6
void TC6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TC6_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
#ifdef ID_TC7
void TC7_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TC7_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
void PDEC_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* PDEC_DIR_A, PDEC_ERR_A, PDEC_OVF, PDEC_VLC_A */
void PDEC_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* PDEC_MC_0 */
void PDEC_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* PDEC_MC_1 */
void ADC0_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* ADC0_OVERRUN, ADC0_WINMON */
void ADC0_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* ADC0_RESRDY */
void ADC1_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* ADC1_OVERRUN, ADC1_WINMON */
void ADC1_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* ADC1_RESRDY */
void AC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void DAC_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_OVERRUN_A_0, DAC_OVERRUN_A_1, DAC_UNDERRUN_A_0, DAC_UNDERRUN_A_1 */
void DAC_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_EMPTY_0 */
void DAC_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_EMPTY_1 */
void DAC_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_RESRDY_0 */
void DAC_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler"))); /* DAC_RESRDY_1 */
void PDEC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* PDEC_DIR_A, PDEC_ERR_A, PDEC_OVF, PDEC_VLC_A */
void PDEC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* PDEC_MC_0 */
void PDEC_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* PDEC_MC_1 */
void ADC0_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* ADC0_OVERRUN, ADC0_WINMON */
void ADC0_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* ADC0_RESRDY */
void ADC1_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* ADC1_OVERRUN, ADC1_WINMON */
void ADC1_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* ADC1_RESRDY */
void AC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void DAC_0_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_OVERRUN_A_0, DAC_OVERRUN_A_1, DAC_UNDERRUN_A_0, DAC_UNDERRUN_A_1 */
void DAC_1_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_EMPTY_0 */
void DAC_2_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_EMPTY_1 */
void DAC_3_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_RESRDY_0 */
void DAC_4_Handler(void) __attribute__((weak, alias("Dummy_Handler"))); /* DAC_RESRDY_1 */
#ifdef ID_I2S
void I2S_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void I2S_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
void PCC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void AES_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void TRNG_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void PCC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void AES_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
void TRNG_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#ifdef ID_ICM
void ICM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void ICM_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
#ifdef ID_PUKCC
void PUKCC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void PUKCC_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
void QSPI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void QSPI_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#ifdef ID_SDHC0
void SDHC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void SDHC0_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
#ifdef ID_SDHC1
void SDHC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
void SDHC1_Handler(void) __attribute__((weak, alias("Dummy_Handler")));
#endif
/* Exception Table */
__attribute__ ((section(".vectors")))
const DeviceVectors exception_table = {
__attribute__((section(".vectors"))) const DeviceVectors exception_table = {
/* Configure Initial Stack Pointer, using linker-generated symbols */
.pvStack = (void*) (&_estack),
/* Configure Initial Stack Pointer, using linker-generated symbols */
.pvStack = (void *)(&_estack),
.pfnReset_Handler = (void*) Reset_Handler,
.pfnNMI_Handler = (void*) NMI_Handler,
.pfnHardFault_Handler = (void*) HardFault_Handler,
.pfnMemManage_Handler = (void*) MemManage_Handler,
.pfnBusFault_Handler = (void*) BusFault_Handler,
.pfnUsageFault_Handler = (void*) UsageFault_Handler,
.pvReservedM9 = (void*) (0UL), /* Reserved */
.pvReservedM8 = (void*) (0UL), /* Reserved */
.pvReservedM7 = (void*) (0UL), /* Reserved */
.pvReservedM6 = (void*) (0UL), /* Reserved */
.pfnSVC_Handler = (void*) SVC_Handler,
.pfnDebugMon_Handler = (void*) DebugMon_Handler,
.pvReservedM3 = (void*) (0UL), /* Reserved */
.pfnPendSV_Handler = (void*) PendSV_Handler,
.pfnSysTick_Handler = (void*) SysTick_Handler,
.pfnReset_Handler = (void *)Reset_Handler,
.pfnNMI_Handler = (void *)NMI_Handler,
.pfnHardFault_Handler = (void *)HardFault_Handler,
.pfnMemManage_Handler = (void *)MemManage_Handler,
.pfnBusFault_Handler = (void *)BusFault_Handler,
.pfnUsageFault_Handler = (void *)UsageFault_Handler,
.pvReservedM9 = (void *)(0UL), /* Reserved */
.pvReservedM8 = (void *)(0UL), /* Reserved */
.pvReservedM7 = (void *)(0UL), /* Reserved */
.pvReservedM6 = (void *)(0UL), /* Reserved */
.pfnSVC_Handler = (void *)SVC_Handler,
.pfnDebugMon_Handler = (void *)DebugMon_Handler,
.pvReservedM3 = (void *)(0UL), /* Reserved */
.pfnPendSV_Handler = (void *)PendSV_Handler,
.pfnSysTick_Handler = (void *)SysTick_Handler,
/* Configurable interrupts */
.pfnPM_Handler = (void*) PM_Handler, /* 0 Power Manager */
.pfnMCLK_Handler = (void*) MCLK_Handler, /* 1 Main Clock */
.pfnOSCCTRL_0_Handler = (void*) OSCCTRL_0_Handler, /* 2 OSCCTRL_XOSCFAIL_0, OSCCTRL_XOSCRDY_0 */
.pfnOSCCTRL_1_Handler = (void*) OSCCTRL_1_Handler, /* 3 OSCCTRL_XOSCFAIL_1, OSCCTRL_XOSCRDY_1 */
.pfnOSCCTRL_2_Handler = (void*) OSCCTRL_2_Handler, /* 4 OSCCTRL_DFLLLOCKC, OSCCTRL_DFLLLOCKF, OSCCTRL_DFLLOOB, OSCCTRL_DFLLRCS, OSCCTRL_DFLLRDY */
.pfnOSCCTRL_3_Handler = (void*) OSCCTRL_3_Handler, /* 5 OSCCTRL_DPLLLCKF_0, OSCCTRL_DPLLLCKR_0, OSCCTRL_DPLLLDRTO_0, OSCCTRL_DPLLLTO_0 */
.pfnOSCCTRL_4_Handler = (void*) OSCCTRL_4_Handler, /* 6 OSCCTRL_DPLLLCKF_1, OSCCTRL_DPLLLCKR_1, OSCCTRL_DPLLLDRTO_1, OSCCTRL_DPLLLTO_1 */
.pfnOSC32KCTRL_Handler = (void*) OSC32KCTRL_Handler, /* 7 32kHz Oscillators Control */
.pfnSUPC_0_Handler = (void*) SUPC_0_Handler, /* 8 SUPC_B12SRDY, SUPC_B33SRDY, SUPC_BOD12RDY, SUPC_BOD33RDY, SUPC_VCORERDY, SUPC_VREGRDY */
.pfnSUPC_1_Handler = (void*) SUPC_1_Handler, /* 9 SUPC_BOD12DET, SUPC_BOD33DET */
.pfnWDT_Handler = (void*) WDT_Handler, /* 10 Watchdog Timer */
.pfnRTC_Handler = (void*) RTC_Handler, /* 11 Real-Time Counter */
.pfnEIC_0_Handler = (void*) EIC_0_Handler, /* 12 EIC_EXTINT_0 */
.pfnEIC_1_Handler = (void*) EIC_1_Handler, /* 13 EIC_EXTINT_1 */
.pfnEIC_2_Handler = (void*) EIC_2_Handler, /* 14 EIC_EXTINT_2 */
.pfnEIC_3_Handler = (void*) EIC_3_Handler, /* 15 EIC_EXTINT_3 */
.pfnEIC_4_Handler = (void*) EIC_4_Handler, /* 16 EIC_EXTINT_4 */
.pfnEIC_5_Handler = (void*) EIC_5_Handler, /* 17 EIC_EXTINT_5 */
.pfnEIC_6_Handler = (void*) EIC_6_Handler, /* 18 EIC_EXTINT_6 */
.pfnEIC_7_Handler = (void*) EIC_7_Handler, /* 19 EIC_EXTINT_7 */
.pfnEIC_8_Handler = (void*) EIC_8_Handler, /* 20 EIC_EXTINT_8 */
.pfnEIC_9_Handler = (void*) EIC_9_Handler, /* 21 EIC_EXTINT_9 */
.pfnEIC_10_Handler = (void*) EIC_10_Handler, /* 22 EIC_EXTINT_10 */
.pfnEIC_11_Handler = (void*) EIC_11_Handler, /* 23 EIC_EXTINT_11 */
.pfnEIC_12_Handler = (void*) EIC_12_Handler, /* 24 EIC_EXTINT_12 */
.pfnEIC_13_Handler = (void*) EIC_13_Handler, /* 25 EIC_EXTINT_13 */
.pfnEIC_14_Handler = (void*) EIC_14_Handler, /* 26 EIC_EXTINT_14 */
.pfnEIC_15_Handler = (void*) EIC_15_Handler, /* 27 EIC_EXTINT_15 */
.pfnFREQM_Handler = (void*) FREQM_Handler, /* 28 Frequency Meter */
.pfnNVMCTRL_0_Handler = (void*) NVMCTRL_0_Handler, /* 29 NVMCTRL_0, NVMCTRL_1, NVMCTRL_2, NVMCTRL_3, NVMCTRL_4, NVMCTRL_5, NVMCTRL_6, NVMCTRL_7 */
.pfnNVMCTRL_1_Handler = (void*) NVMCTRL_1_Handler, /* 30 NVMCTRL_10, NVMCTRL_8, NVMCTRL_9 */
.pfnDMAC_0_Handler = (void*) DMAC_0_Handler, /* 31 DMAC_SUSP_0, DMAC_TCMPL_0, DMAC_TERR_0 */
.pfnDMAC_1_Handler = (void*) DMAC_1_Handler, /* 32 DMAC_SUSP_1, DMAC_TCMPL_1, DMAC_TERR_1 */
.pfnDMAC_2_Handler = (void*) DMAC_2_Handler, /* 33 DMAC_SUSP_2, DMAC_TCMPL_2, DMAC_TERR_2 */
.pfnDMAC_3_Handler = (void*) DMAC_3_Handler, /* 34 DMAC_SUSP_3, DMAC_TCMPL_3, DMAC_TERR_3 */
.pfnDMAC_4_Handler = (void*) DMAC_4_Handler, /* 35 DMAC_SUSP_10, DMAC_SUSP_11, DMAC_SUSP_12, DMAC_SUSP_13, DMAC_SUSP_14, DMAC_SUSP_15, DMAC_SUSP_16, DMAC_SUSP_17, DMAC_SUSP_18, DMAC_SUSP_19, DMAC_SUSP_20, DMAC_SUSP_21, DMAC_SUSP_22, DMAC_SUSP_23, DMAC_SUSP_24, DMAC_SUSP_25, DMAC_SUSP_26, DMAC_SUSP_27, DMAC_SUSP_28, DMAC_SUSP_29, DMAC_SUSP_30, DMAC_SUSP_31, DMAC_SUSP_4, DMAC_SUSP_5, DMAC_SUSP_6, DMAC_SUSP_7, DMAC_SUSP_8, DMAC_SUSP_9, DMAC_TCMPL_10, DMAC_TCMPL_11, DMAC_TCMPL_12, DMAC_TCMPL_13, DMAC_TCMPL_14, DMAC_TCMPL_15, DMAC_TCMPL_16, DMAC_TCMPL_17, DMAC_TCMPL_18, DMAC_TCMPL_19, DMAC_TCMPL_20, DMAC_TCMPL_21, DMAC_TCMPL_22, DMAC_TCMPL_23, DMAC_TCMPL_24, DMAC_TCMPL_25, DMAC_TCMPL_26, DMAC_TCMPL_27, DMAC_TCMPL_28, DMAC_TCMPL_29, DMAC_TCMPL_30, DMAC_TCMPL_31, DMAC_TCMPL_4, DMAC_TCMPL_5, DMAC_TCMPL_6, DMAC_TCMPL_7, DMAC_TCMPL_8, DMAC_TCMPL_9, DMAC_TERR_10, DMAC_TERR_11, DMAC_TERR_12, DMAC_TERR_13, DMAC_TERR_14, DMAC_TERR_15, DMAC_TERR_16, DMAC_TERR_17, DMAC_TERR_18, DMAC_TERR_19, DMAC_TERR_20, DMAC_TERR_21, DMAC_TERR_22, DMAC_TERR_23, DMAC_TERR_24, DMAC_TERR_25, DMAC_TERR_26, DMAC_TERR_27, DMAC_TERR_28, DMAC_TERR_29, DMAC_TERR_30, DMAC_TERR_31, DMAC_TERR_4, DMAC_TERR_5, DMAC_TERR_6, DMAC_TERR_7, DMAC_TERR_8, DMAC_TERR_9 */
.pfnEVSYS_0_Handler = (void*) EVSYS_0_Handler, /* 36 EVSYS_EVD_0, EVSYS_OVR_0 */
.pfnEVSYS_1_Handler = (void*) EVSYS_1_Handler, /* 37 EVSYS_EVD_1, EVSYS_OVR_1 */
.pfnEVSYS_2_Handler = (void*) EVSYS_2_Handler, /* 38 EVSYS_EVD_2, EVSYS_OVR_2 */
.pfnEVSYS_3_Handler = (void*) EVSYS_3_Handler, /* 39 EVSYS_EVD_3, EVSYS_OVR_3 */
.pfnEVSYS_4_Handler = (void*) EVSYS_4_Handler, /* 40 EVSYS_EVD_10, EVSYS_EVD_11, EVSYS_EVD_4, EVSYS_EVD_5, EVSYS_EVD_6, EVSYS_EVD_7, EVSYS_EVD_8, EVSYS_EVD_9, EVSYS_OVR_10, EVSYS_OVR_11, EVSYS_OVR_4, EVSYS_OVR_5, EVSYS_OVR_6, EVSYS_OVR_7, EVSYS_OVR_8, EVSYS_OVR_9 */
.pfnPAC_Handler = (void*) PAC_Handler, /* 41 Peripheral Access Controller */
.pfnTAL_0_Handler = (void*) TAL_0_Handler, /* 42 TAL_BRK */
.pfnTAL_1_Handler = (void*) TAL_1_Handler, /* 43 TAL_IPS_0, TAL_IPS_1 */
.pvReserved44 = (void*) (0UL), /* 44 Reserved */
.pfnRAMECC_Handler = (void*) RAMECC_Handler, /* 45 RAM ECC */
.pfnSERCOM0_0_Handler = (void*) SERCOM0_0_Handler, /* 46 SERCOM0_0 */
.pfnSERCOM0_1_Handler = (void*) SERCOM0_1_Handler, /* 47 SERCOM0_1 */
.pfnSERCOM0_2_Handler = (void*) SERCOM0_2_Handler, /* 48 SERCOM0_2 */
.pfnSERCOM0_3_Handler = (void*) SERCOM0_3_Handler, /* 49 SERCOM0_3, SERCOM0_4, SERCOM0_5, SERCOM0_6 */
.pfnSERCOM1_0_Handler = (void*) SERCOM1_0_Handler, /* 50 SERCOM1_0 */
.pfnSERCOM1_1_Handler = (void*) SERCOM1_1_Handler, /* 51 SERCOM1_1 */
.pfnSERCOM1_2_Handler = (void*) SERCOM1_2_Handler, /* 52 SERCOM1_2 */
.pfnSERCOM1_3_Handler = (void*) SERCOM1_3_Handler, /* 53 SERCOM1_3, SERCOM1_4, SERCOM1_5, SERCOM1_6 */
.pfnSERCOM2_0_Handler = (void*) SERCOM2_0_Handler, /* 54 SERCOM2_0 */
.pfnSERCOM2_1_Handler = (void*) SERCOM2_1_Handler, /* 55 SERCOM2_1 */
.pfnSERCOM2_2_Handler = (void*) SERCOM2_2_Handler, /* 56 SERCOM2_2 */
.pfnSERCOM2_3_Handler = (void*) SERCOM2_3_Handler, /* 57 SERCOM2_3, SERCOM2_4, SERCOM2_5, SERCOM2_6 */
.pfnSERCOM3_0_Handler = (void*) SERCOM3_0_Handler, /* 58 SERCOM3_0 */
.pfnSERCOM3_1_Handler = (void*) SERCOM3_1_Handler, /* 59 SERCOM3_1 */
.pfnSERCOM3_2_Handler = (void*) SERCOM3_2_Handler, /* 60 SERCOM3_2 */
.pfnSERCOM3_3_Handler = (void*) SERCOM3_3_Handler, /* 61 SERCOM3_3, SERCOM3_4, SERCOM3_5, SERCOM3_6 */
/* Configurable interrupts */
.pfnPM_Handler = (void *)PM_Handler, /* 0 Power Manager */
.pfnMCLK_Handler = (void *)MCLK_Handler, /* 1 Main Clock */
.pfnOSCCTRL_0_Handler = (void *)OSCCTRL_0_Handler, /* 2 OSCCTRL_XOSCFAIL_0, OSCCTRL_XOSCRDY_0 */
.pfnOSCCTRL_1_Handler = (void *)OSCCTRL_1_Handler, /* 3 OSCCTRL_XOSCFAIL_1, OSCCTRL_XOSCRDY_1 */
.pfnOSCCTRL_2_Handler = (void *)OSCCTRL_2_Handler, /* 4 OSCCTRL_DFLLLOCKC, OSCCTRL_DFLLLOCKF, OSCCTRL_DFLLOOB, OSCCTRL_DFLLRCS, OSCCTRL_DFLLRDY */
.pfnOSCCTRL_3_Handler = (void *)OSCCTRL_3_Handler, /* 5 OSCCTRL_DPLLLCKF_0, OSCCTRL_DPLLLCKR_0, OSCCTRL_DPLLLDRTO_0, OSCCTRL_DPLLLTO_0 */
.pfnOSCCTRL_4_Handler = (void *)OSCCTRL_4_Handler, /* 6 OSCCTRL_DPLLLCKF_1, OSCCTRL_DPLLLCKR_1, OSCCTRL_DPLLLDRTO_1, OSCCTRL_DPLLLTO_1 */
.pfnOSC32KCTRL_Handler = (void *)OSC32KCTRL_Handler, /* 7 32kHz Oscillators Control */
.pfnSUPC_0_Handler = (void *)SUPC_0_Handler, /* 8 SUPC_B12SRDY, SUPC_B33SRDY, SUPC_BOD12RDY, SUPC_BOD33RDY, SUPC_VCORERDY, SUPC_VREGRDY */
.pfnSUPC_1_Handler = (void *)SUPC_1_Handler, /* 9 SUPC_BOD12DET, SUPC_BOD33DET */
.pfnWDT_Handler = (void *)WDT_Handler, /* 10 Watchdog Timer */
.pfnRTC_Handler = (void *)RTC_Handler, /* 11 Real-Time Counter */
.pfnEIC_0_Handler = (void *)EIC_0_Handler, /* 12 EIC_EXTINT_0 */
.pfnEIC_1_Handler = (void *)EIC_1_Handler, /* 13 EIC_EXTINT_1 */
.pfnEIC_2_Handler = (void *)EIC_2_Handler, /* 14 EIC_EXTINT_2 */
.pfnEIC_3_Handler = (void *)EIC_3_Handler, /* 15 EIC_EXTINT_3 */
.pfnEIC_4_Handler = (void *)EIC_4_Handler, /* 16 EIC_EXTINT_4 */
.pfnEIC_5_Handler = (void *)EIC_5_Handler, /* 17 EIC_EXTINT_5 */
.pfnEIC_6_Handler = (void *)EIC_6_Handler, /* 18 EIC_EXTINT_6 */
.pfnEIC_7_Handler = (void *)EIC_7_Handler, /* 19 EIC_EXTINT_7 */
.pfnEIC_8_Handler = (void *)EIC_8_Handler, /* 20 EIC_EXTINT_8 */
.pfnEIC_9_Handler = (void *)EIC_9_Handler, /* 21 EIC_EXTINT_9 */
.pfnEIC_10_Handler = (void *)EIC_10_Handler, /* 22 EIC_EXTINT_10 */
.pfnEIC_11_Handler = (void *)EIC_11_Handler, /* 23 EIC_EXTINT_11 */
.pfnEIC_12_Handler = (void *)EIC_12_Handler, /* 24 EIC_EXTINT_12 */
.pfnEIC_13_Handler = (void *)EIC_13_Handler, /* 25 EIC_EXTINT_13 */
.pfnEIC_14_Handler = (void *)EIC_14_Handler, /* 26 EIC_EXTINT_14 */
.pfnEIC_15_Handler = (void *)EIC_15_Handler, /* 27 EIC_EXTINT_15 */
.pfnFREQM_Handler = (void *)FREQM_Handler, /* 28 Frequency Meter */
.pfnNVMCTRL_0_Handler = (void *)NVMCTRL_0_Handler, /* 29 NVMCTRL_0, NVMCTRL_1, NVMCTRL_2, NVMCTRL_3, NVMCTRL_4, NVMCTRL_5, NVMCTRL_6, NVMCTRL_7 */
.pfnNVMCTRL_1_Handler = (void *)NVMCTRL_1_Handler, /* 30 NVMCTRL_10, NVMCTRL_8, NVMCTRL_9 */
.pfnDMAC_0_Handler = (void *)DMAC_0_Handler, /* 31 DMAC_SUSP_0, DMAC_TCMPL_0, DMAC_TERR_0 */
.pfnDMAC_1_Handler = (void *)DMAC_1_Handler, /* 32 DMAC_SUSP_1, DMAC_TCMPL_1, DMAC_TERR_1 */
.pfnDMAC_2_Handler = (void *)DMAC_2_Handler, /* 33 DMAC_SUSP_2, DMAC_TCMPL_2, DMAC_TERR_2 */
.pfnDMAC_3_Handler = (void *)DMAC_3_Handler, /* 34 DMAC_SUSP_3, DMAC_TCMPL_3, DMAC_TERR_3 */
.pfnDMAC_4_Handler = (void *)DMAC_4_Handler, /* 35 DMAC_SUSP_10, DMAC_SUSP_11, DMAC_SUSP_12, DMAC_SUSP_13, DMAC_SUSP_14, DMAC_SUSP_15, DMAC_SUSP_16, DMAC_SUSP_17, DMAC_SUSP_18, DMAC_SUSP_19, DMAC_SUSP_20, DMAC_SUSP_21, DMAC_SUSP_22, DMAC_SUSP_23, DMAC_SUSP_24, DMAC_SUSP_25, DMAC_SUSP_26, DMAC_SUSP_27, DMAC_SUSP_28, DMAC_SUSP_29, DMAC_SUSP_30, DMAC_SUSP_31, DMAC_SUSP_4, DMAC_SUSP_5, DMAC_SUSP_6, DMAC_SUSP_7, DMAC_SUSP_8, DMAC_SUSP_9, DMAC_TCMPL_10, DMAC_TCMPL_11, DMAC_TCMPL_12, DMAC_TCMPL_13, DMAC_TCMPL_14, DMAC_TCMPL_15, DMAC_TCMPL_16, DMAC_TCMPL_17, DMAC_TCMPL_18, DMAC_TCMPL_19, DMAC_TCMPL_20, DMAC_TCMPL_21, DMAC_TCMPL_22, DMAC_TCMPL_23, DMAC_TCMPL_24, DMAC_TCMPL_25, DMAC_TCMPL_26, DMAC_TCMPL_27, DMAC_TCMPL_28, DMAC_TCMPL_29, DMAC_TCMPL_30, DMAC_TCMPL_31, DMAC_TCMPL_4, DMAC_TCMPL_5, DMAC_TCMPL_6, DMAC_TCMPL_7, DMAC_TCMPL_8, DMAC_TCMPL_9, DMAC_TERR_10, DMAC_TERR_11, DMAC_TERR_12, DMAC_TERR_13, DMAC_TERR_14, DMAC_TERR_15, DMAC_TERR_16, DMAC_TERR_17, DMAC_TERR_18, DMAC_TERR_19,
DMAC_TERR_20, DMAC_TERR_21, DMAC_TERR_22, DMAC_TERR_23, DMAC_TERR_24, DMAC_TERR_25, DMAC_TERR_26, DMAC_TERR_27, DMAC_TERR_28, DMAC_TERR_29, DMAC_TERR_30, DMAC_TERR_31, DMAC_TERR_4, DMAC_TERR_5, DMAC_TERR_6, DMAC_TERR_7, DMAC_TERR_8, DMAC_TERR_9 */
.pfnEVSYS_0_Handler = (void *)EVSYS_0_Handler, /* 36 EVSYS_EVD_0, EVSYS_OVR_0 */
.pfnEVSYS_1_Handler = (void *)EVSYS_1_Handler, /* 37 EVSYS_EVD_1, EVSYS_OVR_1 */
.pfnEVSYS_2_Handler = (void *)EVSYS_2_Handler, /* 38 EVSYS_EVD_2, EVSYS_OVR_2 */
.pfnEVSYS_3_Handler = (void *)EVSYS_3_Handler, /* 39 EVSYS_EVD_3, EVSYS_OVR_3 */
.pfnEVSYS_4_Handler = (void *)EVSYS_4_Handler, /* 40 EVSYS_EVD_10, EVSYS_EVD_11, EVSYS_EVD_4, EVSYS_EVD_5, EVSYS_EVD_6, EVSYS_EVD_7, EVSYS_EVD_8, EVSYS_EVD_9, EVSYS_OVR_10, EVSYS_OVR_11, EVSYS_OVR_4, EVSYS_OVR_5, EVSYS_OVR_6, EVSYS_OVR_7, EVSYS_OVR_8, EVSYS_OVR_9 */
.pfnPAC_Handler = (void *)PAC_Handler, /* 41 Peripheral Access Controller */
.pfnTAL_0_Handler = (void *)TAL_0_Handler, /* 42 TAL_BRK */
.pfnTAL_1_Handler = (void *)TAL_1_Handler, /* 43 TAL_IPS_0, TAL_IPS_1 */
.pvReserved44 = (void *)(0UL), /* 44 Reserved */
.pfnRAMECC_Handler = (void *)RAMECC_Handler, /* 45 RAM ECC */
.pfnSERCOM0_0_Handler = (void *)SERCOM0_0_Handler, /* 46 SERCOM0_0 */
.pfnSERCOM0_1_Handler = (void *)SERCOM0_1_Handler, /* 47 SERCOM0_1 */
.pfnSERCOM0_2_Handler = (void *)SERCOM0_2_Handler, /* 48 SERCOM0_2 */
.pfnSERCOM0_3_Handler = (void *)SERCOM0_3_Handler, /* 49 SERCOM0_3, SERCOM0_4, SERCOM0_5, SERCOM0_6 */
.pfnSERCOM1_0_Handler = (void *)SERCOM1_0_Handler, /* 50 SERCOM1_0 */
.pfnSERCOM1_1_Handler = (void *)SERCOM1_1_Handler, /* 51 SERCOM1_1 */
.pfnSERCOM1_2_Handler = (void *)SERCOM1_2_Handler, /* 52 SERCOM1_2 */
.pfnSERCOM1_3_Handler = (void *)SERCOM1_3_Handler, /* 53 SERCOM1_3, SERCOM1_4, SERCOM1_5, SERCOM1_6 */
.pfnSERCOM2_0_Handler = (void *)SERCOM2_0_Handler, /* 54 SERCOM2_0 */
.pfnSERCOM2_1_Handler = (void *)SERCOM2_1_Handler, /* 55 SERCOM2_1 */
.pfnSERCOM2_2_Handler = (void *)SERCOM2_2_Handler, /* 56 SERCOM2_2 */
.pfnSERCOM2_3_Handler = (void *)SERCOM2_3_Handler, /* 57 SERCOM2_3, SERCOM2_4, SERCOM2_5, SERCOM2_6 */
.pfnSERCOM3_0_Handler = (void *)SERCOM3_0_Handler, /* 58 SERCOM3_0 */
.pfnSERCOM3_1_Handler = (void *)SERCOM3_1_Handler, /* 59 SERCOM3_1 */
.pfnSERCOM3_2_Handler = (void *)SERCOM3_2_Handler, /* 60 SERCOM3_2 */
.pfnSERCOM3_3_Handler = (void *)SERCOM3_3_Handler, /* 61 SERCOM3_3, SERCOM3_4, SERCOM3_5, SERCOM3_6 */
#ifdef ID_SERCOM4
.pfnSERCOM4_0_Handler = (void*) SERCOM4_0_Handler, /* 62 SERCOM4_0 */
.pfnSERCOM4_1_Handler = (void*) SERCOM4_1_Handler, /* 63 SERCOM4_1 */
.pfnSERCOM4_2_Handler = (void*) SERCOM4_2_Handler, /* 64 SERCOM4_2 */
.pfnSERCOM4_3_Handler = (void*) SERCOM4_3_Handler, /* 65 SERCOM4_3, SERCOM4_4, SERCOM4_5, SERCOM4_6 */
.pfnSERCOM4_0_Handler = (void *)SERCOM4_0_Handler, /* 62 SERCOM4_0 */
.pfnSERCOM4_1_Handler = (void *)SERCOM4_1_Handler, /* 63 SERCOM4_1 */
.pfnSERCOM4_2_Handler = (void *)SERCOM4_2_Handler, /* 64 SERCOM4_2 */
.pfnSERCOM4_3_Handler = (void *)SERCOM4_3_Handler, /* 65 SERCOM4_3, SERCOM4_4, SERCOM4_5, SERCOM4_6 */
#else
.pvReserved62 = (void*) (0UL), /* 62 Reserved */
.pvReserved63 = (void*) (0UL), /* 63 Reserved */
.pvReserved64 = (void*) (0UL), /* 64 Reserved */
.pvReserved65 = (void*) (0UL), /* 65 Reserved */
.pvReserved62 = (void *)(0UL), /* 62 Reserved */
.pvReserved63 = (void *)(0UL), /* 63 Reserved */
.pvReserved64 = (void *)(0UL), /* 64 Reserved */
.pvReserved65 = (void *)(0UL), /* 65 Reserved */
#endif
#ifdef ID_SERCOM5
.pfnSERCOM5_0_Handler = (void*) SERCOM5_0_Handler, /* 66 SERCOM5_0 */
.pfnSERCOM5_1_Handler = (void*) SERCOM5_1_Handler, /* 67 SERCOM5_1 */
.pfnSERCOM5_2_Handler = (void*) SERCOM5_2_Handler, /* 68 SERCOM5_2 */
.pfnSERCOM5_3_Handler = (void*) SERCOM5_3_Handler, /* 69 SERCOM5_3, SERCOM5_4, SERCOM5_5, SERCOM5_6 */
.pfnSERCOM5_0_Handler = (void *)SERCOM5_0_Handler, /* 66 SERCOM5_0 */
.pfnSERCOM5_1_Handler = (void *)SERCOM5_1_Handler, /* 67 SERCOM5_1 */
.pfnSERCOM5_2_Handler = (void *)SERCOM5_2_Handler, /* 68 SERCOM5_2 */
.pfnSERCOM5_3_Handler = (void *)SERCOM5_3_Handler, /* 69 SERCOM5_3, SERCOM5_4, SERCOM5_5, SERCOM5_6 */
#else
.pvReserved66 = (void*) (0UL), /* 66 Reserved */
.pvReserved67 = (void*) (0UL), /* 67 Reserved */
.pvReserved68 = (void*) (0UL), /* 68 Reserved */
.pvReserved69 = (void*) (0UL), /* 69 Reserved */
.pvReserved66 = (void *)(0UL), /* 66 Reserved */
.pvReserved67 = (void *)(0UL), /* 67 Reserved */
.pvReserved68 = (void *)(0UL), /* 68 Reserved */
.pvReserved69 = (void *)(0UL), /* 69 Reserved */
#endif
#ifdef ID_SERCOM6
.pfnSERCOM6_0_Handler = (void*) SERCOM6_0_Handler, /* 70 SERCOM6_0 */
.pfnSERCOM6_1_Handler = (void*) SERCOM6_1_Handler, /* 71 SERCOM6_1 */
.pfnSERCOM6_2_Handler = (void*) SERCOM6_2_Handler, /* 72 SERCOM6_2 */
.pfnSERCOM6_3_Handler = (void*) SERCOM6_3_Handler, /* 73 SERCOM6_3, SERCOM6_4, SERCOM6_5, SERCOM6_6 */
.pfnSERCOM6_0_Handler = (void *)SERCOM6_0_Handler, /* 70 SERCOM6_0 */
.pfnSERCOM6_1_Handler = (void *)SERCOM6_1_Handler, /* 71 SERCOM6_1 */
.pfnSERCOM6_2_Handler = (void *)SERCOM6_2_Handler, /* 72 SERCOM6_2 */
.pfnSERCOM6_3_Handler = (void *)SERCOM6_3_Handler, /* 73 SERCOM6_3, SERCOM6_4, SERCOM6_5, SERCOM6_6 */
#else
.pvReserved70 = (void*) (0UL), /* 70 Reserved */
.pvReserved71 = (void*) (0UL), /* 71 Reserved */
.pvReserved72 = (void*) (0UL), /* 72 Reserved */
.pvReserved73 = (void*) (0UL), /* 73 Reserved */
.pvReserved70 = (void *)(0UL), /* 70 Reserved */
.pvReserved71 = (void *)(0UL), /* 71 Reserved */
.pvReserved72 = (void *)(0UL), /* 72 Reserved */
.pvReserved73 = (void *)(0UL), /* 73 Reserved */
#endif
#ifdef ID_SERCOM7
.pfnSERCOM7_0_Handler = (void*) SERCOM7_0_Handler, /* 74 SERCOM7_0 */
.pfnSERCOM7_1_Handler = (void*) SERCOM7_1_Handler, /* 75 SERCOM7_1 */
.pfnSERCOM7_2_Handler = (void*) SERCOM7_2_Handler, /* 76 SERCOM7_2 */
.pfnSERCOM7_3_Handler = (void*) SERCOM7_3_Handler, /* 77 SERCOM7_3, SERCOM7_4, SERCOM7_5, SERCOM7_6 */
.pfnSERCOM7_0_Handler = (void *)SERCOM7_0_Handler, /* 74 SERCOM7_0 */
.pfnSERCOM7_1_Handler = (void *)SERCOM7_1_Handler, /* 75 SERCOM7_1 */
.pfnSERCOM7_2_Handler = (void *)SERCOM7_2_Handler, /* 76 SERCOM7_2 */
.pfnSERCOM7_3_Handler = (void *)SERCOM7_3_Handler, /* 77 SERCOM7_3, SERCOM7_4, SERCOM7_5, SERCOM7_6 */
#else
.pvReserved74 = (void*) (0UL), /* 74 Reserved */
.pvReserved75 = (void*) (0UL), /* 75 Reserved */
.pvReserved76 = (void*) (0UL), /* 76 Reserved */
.pvReserved77 = (void*) (0UL), /* 77 Reserved */
.pvReserved74 = (void *)(0UL), /* 74 Reserved */
.pvReserved75 = (void *)(0UL), /* 75 Reserved */
.pvReserved76 = (void *)(0UL), /* 76 Reserved */
.pvReserved77 = (void *)(0UL), /* 77 Reserved */
#endif
#ifdef ID_CAN0
.pfnCAN0_Handler = (void*) CAN0_Handler, /* 78 Control Area Network 0 */
.pfnCAN0_Handler = (void *)CAN0_Handler, /* 78 Control Area Network 0 */
#else
.pvReserved78 = (void*) (0UL), /* 78 Reserved */
.pvReserved78 = (void *)(0UL), /* 78 Reserved */
#endif
#ifdef ID_CAN1
.pfnCAN1_Handler = (void*) CAN1_Handler, /* 79 Control Area Network 1 */
.pfnCAN1_Handler = (void *)CAN1_Handler, /* 79 Control Area Network 1 */
#else
.pvReserved79 = (void*) (0UL), /* 79 Reserved */
.pvReserved79 = (void *)(0UL), /* 79 Reserved */
#endif
#ifdef ID_USB
.pfnUSB_0_Handler = (void*) USB_0_Handler, /* 80 USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN, USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1, USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4, USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7, USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2, USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5, USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1, USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6, USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1, USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4, USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7, USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2, USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5, USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
.pfnUSB_1_Handler = (void*) USB_1_Handler, /* 81 USB_SOF_HSOF */
.pfnUSB_2_Handler = (void*) USB_2_Handler, /* 82 USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2, USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5, USB_TRCPT0_6, USB_TRCPT0_7 */
.pfnUSB_3_Handler = (void*) USB_3_Handler, /* 83 USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2, USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5, USB_TRCPT1_6, USB_TRCPT1_7 */
.pfnUSB_0_Handler = (void *)USB_0_Handler, /* 80 USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN, USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1, USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4, USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7, USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2, USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5, USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1, USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6, USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1, USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4, USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7, USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2, USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5, USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
.pfnUSB_1_Handler = (void *)USB_1_Handler, /* 81 USB_SOF_HSOF */
.pfnUSB_2_Handler = (void *)USB_2_Handler, /* 82 USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2, USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5, USB_TRCPT0_6, USB_TRCPT0_7 */
.pfnUSB_3_Handler = (void *)USB_3_Handler, /* 83 USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2, USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5, USB_TRCPT1_6, USB_TRCPT1_7 */
#else
.pvReserved80 = (void*) (0UL), /* 80 Reserved */
.pvReserved81 = (void*) (0UL), /* 81 Reserved */
.pvReserved82 = (void*) (0UL), /* 82 Reserved */
.pvReserved83 = (void*) (0UL), /* 83 Reserved */
.pvReserved80 = (void *)(0UL), /* 80 Reserved */
.pvReserved81 = (void *)(0UL), /* 81 Reserved */
.pvReserved82 = (void *)(0UL), /* 82 Reserved */
.pvReserved83 = (void *)(0UL), /* 83 Reserved */
#endif
#ifdef ID_GMAC
.pfnGMAC_Handler = (void*) GMAC_Handler, /* 84 Ethernet MAC */
.pfnGMAC_Handler = (void *)GMAC_Handler, /* 84 Ethernet MAC */
#else
.pvReserved84 = (void*) (0UL), /* 84 Reserved */
.pvReserved84 = (void *)(0UL), /* 84 Reserved */
#endif
.pfnTCC0_0_Handler = (void*) TCC0_0_Handler, /* 85 TCC0_CNT_A, TCC0_DFS_A, TCC0_ERR_A, TCC0_FAULT0_A, TCC0_FAULT1_A, TCC0_FAULTA_A, TCC0_FAULTB_A, TCC0_OVF, TCC0_TRG, TCC0_UFS_A */
.pfnTCC0_1_Handler = (void*) TCC0_1_Handler, /* 86 TCC0_MC_0 */
.pfnTCC0_2_Handler = (void*) TCC0_2_Handler, /* 87 TCC0_MC_1 */
.pfnTCC0_3_Handler = (void*) TCC0_3_Handler, /* 88 TCC0_MC_2 */
.pfnTCC0_4_Handler = (void*) TCC0_4_Handler, /* 89 TCC0_MC_3 */
.pfnTCC0_5_Handler = (void*) TCC0_5_Handler, /* 90 TCC0_MC_4 */
.pfnTCC0_6_Handler = (void*) TCC0_6_Handler, /* 91 TCC0_MC_5 */
.pfnTCC1_0_Handler = (void*) TCC1_0_Handler, /* 92 TCC1_CNT_A, TCC1_DFS_A, TCC1_ERR_A, TCC1_FAULT0_A, TCC1_FAULT1_A, TCC1_FAULTA_A, TCC1_FAULTB_A, TCC1_OVF, TCC1_TRG, TCC1_UFS_A */
.pfnTCC1_1_Handler = (void*) TCC1_1_Handler, /* 93 TCC1_MC_0 */
.pfnTCC1_2_Handler = (void*) TCC1_2_Handler, /* 94 TCC1_MC_1 */
.pfnTCC1_3_Handler = (void*) TCC1_3_Handler, /* 95 TCC1_MC_2 */
.pfnTCC1_4_Handler = (void*) TCC1_4_Handler, /* 96 TCC1_MC_3 */
.pfnTCC2_0_Handler = (void*) TCC2_0_Handler, /* 97 TCC2_CNT_A, TCC2_DFS_A, TCC2_ERR_A, TCC2_FAULT0_A, TCC2_FAULT1_A, TCC2_FAULTA_A, TCC2_FAULTB_A, TCC2_OVF, TCC2_TRG, TCC2_UFS_A */
.pfnTCC2_1_Handler = (void*) TCC2_1_Handler, /* 98 TCC2_MC_0 */
.pfnTCC2_2_Handler = (void*) TCC2_2_Handler, /* 99 TCC2_MC_1 */
.pfnTCC2_3_Handler = (void*) TCC2_3_Handler, /* 100 TCC2_MC_2 */
.pfnTCC0_0_Handler = (void *)TCC0_0_Handler, /* 85 TCC0_CNT_A, TCC0_DFS_A, TCC0_ERR_A, TCC0_FAULT0_A, TCC0_FAULT1_A, TCC0_FAULTA_A, TCC0_FAULTB_A, TCC0_OVF, TCC0_TRG, TCC0_UFS_A */
.pfnTCC0_1_Handler = (void *)TCC0_1_Handler, /* 86 TCC0_MC_0 */
.pfnTCC0_2_Handler = (void *)TCC0_2_Handler, /* 87 TCC0_MC_1 */
.pfnTCC0_3_Handler = (void *)TCC0_3_Handler, /* 88 TCC0_MC_2 */
.pfnTCC0_4_Handler = (void *)TCC0_4_Handler, /* 89 TCC0_MC_3 */
.pfnTCC0_5_Handler = (void *)TCC0_5_Handler, /* 90 TCC0_MC_4 */
.pfnTCC0_6_Handler = (void *)TCC0_6_Handler, /* 91 TCC0_MC_5 */
.pfnTCC1_0_Handler = (void *)TCC1_0_Handler, /* 92 TCC1_CNT_A, TCC1_DFS_A, TCC1_ERR_A, TCC1_FAULT0_A, TCC1_FAULT1_A, TCC1_FAULTA_A, TCC1_FAULTB_A, TCC1_OVF, TCC1_TRG, TCC1_UFS_A */
.pfnTCC1_1_Handler = (void *)TCC1_1_Handler, /* 93 TCC1_MC_0 */
.pfnTCC1_2_Handler = (void *)TCC1_2_Handler, /* 94 TCC1_MC_1 */
.pfnTCC1_3_Handler = (void *)TCC1_3_Handler, /* 95 TCC1_MC_2 */
.pfnTCC1_4_Handler = (void *)TCC1_4_Handler, /* 96 TCC1_MC_3 */
.pfnTCC2_0_Handler = (void *)TCC2_0_Handler, /* 97 TCC2_CNT_A, TCC2_DFS_A, TCC2_ERR_A, TCC2_FAULT0_A, TCC2_FAULT1_A, TCC2_FAULTA_A, TCC2_FAULTB_A, TCC2_OVF, TCC2_TRG, TCC2_UFS_A */
.pfnTCC2_1_Handler = (void *)TCC2_1_Handler, /* 98 TCC2_MC_0 */
.pfnTCC2_2_Handler = (void *)TCC2_2_Handler, /* 99 TCC2_MC_1 */
.pfnTCC2_3_Handler = (void *)TCC2_3_Handler, /* 100 TCC2_MC_2 */
#ifdef ID_TCC3
.pfnTCC3_0_Handler = (void*) TCC3_0_Handler, /* 101 TCC3_CNT_A, TCC3_DFS_A, TCC3_ERR_A, TCC3_FAULT0_A, TCC3_FAULT1_A, TCC3_FAULTA_A, TCC3_FAULTB_A, TCC3_OVF, TCC3_TRG, TCC3_UFS_A */
.pfnTCC3_1_Handler = (void*) TCC3_1_Handler, /* 102 TCC3_MC_0 */
.pfnTCC3_2_Handler = (void*) TCC3_2_Handler, /* 103 TCC3_MC_1 */
.pfnTCC3_0_Handler = (void *)TCC3_0_Handler, /* 101 TCC3_CNT_A, TCC3_DFS_A, TCC3_ERR_A, TCC3_FAULT0_A, TCC3_FAULT1_A, TCC3_FAULTA_A, TCC3_FAULTB_A, TCC3_OVF, TCC3_TRG, TCC3_UFS_A */
.pfnTCC3_1_Handler = (void *)TCC3_1_Handler, /* 102 TCC3_MC_0 */
.pfnTCC3_2_Handler = (void *)TCC3_2_Handler, /* 103 TCC3_MC_1 */
#else
.pvReserved101 = (void*) (0UL), /* 101 Reserved */
.pvReserved102 = (void*) (0UL), /* 102 Reserved */
.pvReserved103 = (void*) (0UL), /* 103 Reserved */
.pvReserved101 = (void *)(0UL), /* 101 Reserved */
.pvReserved102 = (void *)(0UL), /* 102 Reserved */
.pvReserved103 = (void *)(0UL), /* 103 Reserved */
#endif
#ifdef ID_TCC4
.pfnTCC4_0_Handler = (void*) TCC4_0_Handler, /* 104 TCC4_CNT_A, TCC4_DFS_A, TCC4_ERR_A, TCC4_FAULT0_A, TCC4_FAULT1_A, TCC4_FAULTA_A, TCC4_FAULTB_A, TCC4_OVF, TCC4_TRG, TCC4_UFS_A */
.pfnTCC4_1_Handler = (void*) TCC4_1_Handler, /* 105 TCC4_MC_0 */
.pfnTCC4_2_Handler = (void*) TCC4_2_Handler, /* 106 TCC4_MC_1 */
.pfnTCC4_0_Handler = (void *)TCC4_0_Handler, /* 104 TCC4_CNT_A, TCC4_DFS_A, TCC4_ERR_A, TCC4_FAULT0_A, TCC4_FAULT1_A, TCC4_FAULTA_A, TCC4_FAULTB_A, TCC4_OVF, TCC4_TRG, TCC4_UFS_A */
.pfnTCC4_1_Handler = (void *)TCC4_1_Handler, /* 105 TCC4_MC_0 */
.pfnTCC4_2_Handler = (void *)TCC4_2_Handler, /* 106 TCC4_MC_1 */
#else
.pvReserved104 = (void*) (0UL), /* 104 Reserved */
.pvReserved105 = (void*) (0UL), /* 105 Reserved */
.pvReserved106 = (void*) (0UL), /* 106 Reserved */
.pvReserved104 = (void *)(0UL), /* 104 Reserved */
.pvReserved105 = (void *)(0UL), /* 105 Reserved */
.pvReserved106 = (void *)(0UL), /* 106 Reserved */
#endif
.pfnTC0_Handler = (void*) TC0_Handler, /* 107 Basic Timer Counter 0 */
.pfnTC1_Handler = (void*) TC1_Handler, /* 108 Basic Timer Counter 1 */
.pfnTC2_Handler = (void*) TC2_Handler, /* 109 Basic Timer Counter 2 */
.pfnTC3_Handler = (void*) TC3_Handler, /* 110 Basic Timer Counter 3 */
.pfnTC0_Handler = (void *)TC0_Handler, /* 107 Basic Timer Counter 0 */
.pfnTC1_Handler = (void *)TC1_Handler, /* 108 Basic Timer Counter 1 */
.pfnTC2_Handler = (void *)TC2_Handler, /* 109 Basic Timer Counter 2 */
.pfnTC3_Handler = (void *)TC3_Handler, /* 110 Basic Timer Counter 3 */
#ifdef ID_TC4
.pfnTC4_Handler = (void*) TC4_Handler, /* 111 Basic Timer Counter 4 */
.pfnTC4_Handler = (void *)TC4_Handler, /* 111 Basic Timer Counter 4 */
#else
.pvReserved111 = (void*) (0UL), /* 111 Reserved */
.pvReserved111 = (void *)(0UL), /* 111 Reserved */
#endif
#ifdef ID_TC5
.pfnTC5_Handler = (void*) TC5_Handler, /* 112 Basic Timer Counter 5 */
.pfnTC5_Handler = (void *)TC5_Handler, /* 112 Basic Timer Counter 5 */
#else
.pvReserved112 = (void*) (0UL), /* 112 Reserved */
.pvReserved112 = (void *)(0UL), /* 112 Reserved */
#endif
#ifdef ID_TC6
.pfnTC6_Handler = (void*) TC6_Handler, /* 113 Basic Timer Counter 6 */
.pfnTC6_Handler = (void *)TC6_Handler, /* 113 Basic Timer Counter 6 */
#else
.pvReserved113 = (void*) (0UL), /* 113 Reserved */
.pvReserved113 = (void *)(0UL), /* 113 Reserved */
#endif
#ifdef ID_TC7
.pfnTC7_Handler = (void*) TC7_Handler, /* 114 Basic Timer Counter 7 */
.pfnTC7_Handler = (void *)TC7_Handler, /* 114 Basic Timer Counter 7 */
#else
.pvReserved114 = (void*) (0UL), /* 114 Reserved */
.pvReserved114 = (void *)(0UL), /* 114 Reserved */
#endif
.pfnPDEC_0_Handler = (void*) PDEC_0_Handler, /* 115 PDEC_DIR_A, PDEC_ERR_A, PDEC_OVF, PDEC_VLC_A */
.pfnPDEC_1_Handler = (void*) PDEC_1_Handler, /* 116 PDEC_MC_0 */
.pfnPDEC_2_Handler = (void*) PDEC_2_Handler, /* 117 PDEC_MC_1 */
.pfnADC0_0_Handler = (void*) ADC0_0_Handler, /* 118 ADC0_OVERRUN, ADC0_WINMON */
.pfnADC0_1_Handler = (void*) ADC0_1_Handler, /* 119 ADC0_RESRDY */
.pfnADC1_0_Handler = (void*) ADC1_0_Handler, /* 120 ADC1_OVERRUN, ADC1_WINMON */
.pfnADC1_1_Handler = (void*) ADC1_1_Handler, /* 121 ADC1_RESRDY */
.pfnAC_Handler = (void*) AC_Handler, /* 122 Analog Comparators */
.pfnDAC_0_Handler = (void*) DAC_0_Handler, /* 123 DAC_OVERRUN_A_0, DAC_OVERRUN_A_1, DAC_UNDERRUN_A_0, DAC_UNDERRUN_A_1 */
.pfnDAC_1_Handler = (void*) DAC_1_Handler, /* 124 DAC_EMPTY_0 */
.pfnDAC_2_Handler = (void*) DAC_2_Handler, /* 125 DAC_EMPTY_1 */
.pfnDAC_3_Handler = (void*) DAC_3_Handler, /* 126 DAC_RESRDY_0 */
.pfnDAC_4_Handler = (void*) DAC_4_Handler, /* 127 DAC_RESRDY_1 */
.pfnPDEC_0_Handler = (void *)PDEC_0_Handler, /* 115 PDEC_DIR_A, PDEC_ERR_A, PDEC_OVF, PDEC_VLC_A */
.pfnPDEC_1_Handler = (void *)PDEC_1_Handler, /* 116 PDEC_MC_0 */
.pfnPDEC_2_Handler = (void *)PDEC_2_Handler, /* 117 PDEC_MC_1 */
.pfnADC0_0_Handler = (void *)ADC0_0_Handler, /* 118 ADC0_OVERRUN, ADC0_WINMON */
.pfnADC0_1_Handler = (void *)ADC0_1_Handler, /* 119 ADC0_RESRDY */
.pfnADC1_0_Handler = (void *)ADC1_0_Handler, /* 120 ADC1_OVERRUN, ADC1_WINMON */
.pfnADC1_1_Handler = (void *)ADC1_1_Handler, /* 121 ADC1_RESRDY */
.pfnAC_Handler = (void *)AC_Handler, /* 122 Analog Comparators */
.pfnDAC_0_Handler = (void *)DAC_0_Handler, /* 123 DAC_OVERRUN_A_0, DAC_OVERRUN_A_1, DAC_UNDERRUN_A_0, DAC_UNDERRUN_A_1 */
.pfnDAC_1_Handler = (void *)DAC_1_Handler, /* 124 DAC_EMPTY_0 */
.pfnDAC_2_Handler = (void *)DAC_2_Handler, /* 125 DAC_EMPTY_1 */
.pfnDAC_3_Handler = (void *)DAC_3_Handler, /* 126 DAC_RESRDY_0 */
.pfnDAC_4_Handler = (void *)DAC_4_Handler, /* 127 DAC_RESRDY_1 */
#ifdef ID_I2S
.pfnI2S_Handler = (void*) I2S_Handler, /* 128 Inter-IC Sound Interface */
.pfnI2S_Handler = (void *)I2S_Handler, /* 128 Inter-IC Sound Interface */
#else
.pvReserved128 = (void*) (0UL), /* 128 Reserved */
.pvReserved128 = (void *)(0UL), /* 128 Reserved */
#endif
.pfnPCC_Handler = (void*) PCC_Handler, /* 129 Parallel Capture Controller */
.pfnAES_Handler = (void*) AES_Handler, /* 130 Advanced Encryption Standard */
.pfnTRNG_Handler = (void*) TRNG_Handler, /* 131 True Random Generator */
.pfnPCC_Handler = (void *)PCC_Handler, /* 129 Parallel Capture Controller */
.pfnAES_Handler = (void *)AES_Handler, /* 130 Advanced Encryption Standard */
.pfnTRNG_Handler = (void *)TRNG_Handler, /* 131 True Random Generator */
#ifdef ID_ICM
.pfnICM_Handler = (void*) ICM_Handler, /* 132 Integrity Check Monitor */
.pfnICM_Handler = (void *)ICM_Handler, /* 132 Integrity Check Monitor */
#else
.pvReserved132 = (void*) (0UL), /* 132 Reserved */
.pvReserved132 = (void *)(0UL), /* 132 Reserved */
#endif
#ifdef ID_PUKCC
.pfnPUKCC_Handler = (void*) PUKCC_Handler, /* 133 PUblic-Key Cryptography Controller */
.pfnPUKCC_Handler = (void *)PUKCC_Handler, /* 133 PUblic-Key Cryptography Controller */
#else
.pvReserved133 = (void*) (0UL), /* 133 Reserved */
.pvReserved133 = (void *)(0UL), /* 133 Reserved */
#endif
.pfnQSPI_Handler = (void*) QSPI_Handler, /* 134 Quad SPI interface */
.pfnQSPI_Handler = (void *)QSPI_Handler, /* 134 Quad SPI interface */
#ifdef ID_SDHC0
.pfnSDHC0_Handler = (void*) SDHC0_Handler, /* 135 SD/MMC Host Controller 0 */
.pfnSDHC0_Handler = (void *)SDHC0_Handler, /* 135 SD/MMC Host Controller 0 */
#else
.pvReserved135 = (void*) (0UL), /* 135 Reserved */
.pvReserved135 = (void *)(0UL), /* 135 Reserved */
#endif
#ifdef ID_SDHC1
.pfnSDHC1_Handler = (void*) SDHC1_Handler /* 136 SD/MMC Host Controller 1 */
.pfnSDHC1_Handler = (void *)SDHC1_Handler /* 136 SD/MMC Host Controller 1 */
#else
.pvReserved136 = (void*) (0UL) /* 136 Reserved */
.pvReserved136 = (void *)(0UL) /* 136 Reserved */
#endif
};
@ -499,61 +500,60 @@ const DeviceVectors exception_table = {
* \brief This is the code that gets called on processor reset.
* To initialize the device, and call the main() routine.
*/
void Reset_Handler(void)
{
void Reset_Handler(void) {
#ifdef KEYBOARD_massdrop_ctrl
/* WARNING: This is only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support */
if (*MAGIC_ADDR == BOOTLOADER_MAGIC) {
/* At this point, the bootloader's memory is initialized properly, so undo the jump to here, then jump back */
*MAGIC_ADDR = 0x00000000; /* Change value to prevent potential bootloader entrance loop */
__set_MSP(0x20008818); /* MSP according to bootloader */
SCB->VTOR = 0x00000000; /* Vector table back to bootloader's */
asm("bx %0"::"r"(0x00001267)); /* Jump past bootloader RCAUSE check using THUMB */
}
/* WARNING: This is only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support */
if (*MAGIC_ADDR == BOOTLOADER_MAGIC) {
/* At this point, the bootloader's memory is initialized properly, so undo the jump to here, then jump back */
*MAGIC_ADDR = 0x00000000; /* Change value to prevent potential bootloader entrance loop */
__set_MSP(0x20008818); /* MSP according to bootloader */
SCB->VTOR = 0x00000000; /* Vector table back to bootloader's */
asm("bx %0" ::"r"(0x00001267)); /* Jump past bootloader RCAUSE check using THUMB */
}
#endif
uint32_t *pSrc, *pDest;
uint32_t *pSrc, *pDest;
/* Initialize the relocate segment */
pSrc = &_etext;
pDest = &_srelocate;
/* Initialize the relocate segment */
pSrc = &_etext;
pDest = &_srelocate;
if (pSrc != pDest) {
for (; pDest < &_erelocate;) {
*pDest++ = *pSrc++;
}
if (pSrc != pDest) {
for (; pDest < &_erelocate;) {
*pDest++ = *pSrc++;
}
}
/* Clear the zero segment */
for (pDest = &_szero; pDest < &_ezero;) {
*pDest++ = 0;
}
/* Clear the zero segment */
for (pDest = &_szero; pDest < &_ezero;) {
*pDest++ = 0;
}
/* Set the vector table base address */
pSrc = (uint32_t *) & _sfixed;
SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk);
/* Set the vector table base address */
pSrc = (uint32_t *)&_sfixed;
SCB->VTOR = ((uint32_t)pSrc & SCB_VTOR_TBLOFF_Msk);
#if __FPU_USED
/* Enable FPU */
SCB->CPACR |= (0xFu << 20);
__DSB();
__ISB();
/* Enable FPU */
SCB->CPACR |= (0xFu << 20);
__DSB();
__ISB();
#endif
/* Initialize the C library */
__libc_init_array();
/* Initialize the C library */
__libc_init_array();
/* Branch to main function */
main();
/* Branch to main function */
main();
/* Infinite loop */
while (1);
/* Infinite loop */
while (1)
;
}
/**
* \brief Default interrupt handler for unused IRQs.
*/
void Dummy_Handler(void)
{
while (1) {
}
void Dummy_Handler(void) {
while (1) {
}
}

File diff suppressed because it is too large Load diff

View file

@ -50,29 +50,29 @@
#include "compiler.h"
#include "udi_device_conf.h"
#define UDI_CDC_DEFAULT_RATE 115200
#define UDI_CDC_DEFAULT_STOPBITS CDC_STOP_BITS_1
#define UDI_CDC_DEFAULT_PARITY CDC_PAR_NONE
#define UDI_CDC_DEFAULT_DATABITS 8
#define UDI_CDC_DEFAULT_RATE 115200
#define UDI_CDC_DEFAULT_STOPBITS CDC_STOP_BITS_1
#define UDI_CDC_DEFAULT_PARITY CDC_PAR_NONE
#define UDI_CDC_DEFAULT_DATABITS 8
//! Device definition (mandatory)
#define USB_DEVICE_VENDOR_ID VENDOR_ID
#define USB_DEVICE_PRODUCT_ID PRODUCT_ID
#define USB_DEVICE_VERSION DEVICE_VER
#define USB_DEVICE_POWER 500 // Consumption on Vbus line (mA)
#define USB_DEVICE_ATTR (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED)
#define USB_DEVICE_VENDOR_ID VENDOR_ID
#define USB_DEVICE_PRODUCT_ID PRODUCT_ID
#define USB_DEVICE_VERSION DEVICE_VER
#define USB_DEVICE_POWER 500 // Consumption on Vbus line (mA)
#define USB_DEVICE_ATTR (USB_CONFIG_ATTR_REMOTE_WAKEUP | USB_CONFIG_ATTR_BUS_POWERED)
// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED)
// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_SELF_POWERED)
// (USB_CONFIG_ATTR_SELF_POWERED)
// (USB_CONFIG_ATTR_BUS_POWERED)
//! USB Device string definitions (Optional)
#define USB_DEVICE_MANUFACTURE_NAME MANUFACTURER
#define USB_DEVICE_PRODUCT_NAME PRODUCT
#define USB_DEVICE_SERIAL_NAME SERIAL_NUM
#define USB_DEVICE_MANUFACTURE_NAME MANUFACTURER
#define USB_DEVICE_PRODUCT_NAME PRODUCT
#define USB_DEVICE_SERIAL_NAME SERIAL_NUM
//Comment out USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL to prevent ROM lookup of factory programmed serial number
#define USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL
// Comment out USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL to prevent ROM lookup of factory programmed serial number
#define USB_DEVICE_SERIAL_USE_BOOTLOADER_SERIAL
/**
* Device speeds support
@ -82,9 +82,9 @@
//#define USB_DEVICE_LOW_SPEED
//! To authorize the High speed
#if (UC3A3||UC3A4)
#if (UC3A3 || UC3A4)
//#define USB_DEVICE_HS_SUPPORT
#elif (SAM3XA||SAM3U)
#elif (SAM3XA || SAM3U)
//#define USB_DEVICE_HS_SUPPORT
#endif
//@}
@ -93,13 +93,13 @@
* USB Device Callbacks definitions (Optional)
* @{
*/
#define UDC_VBUS_EVENT(b_vbus_high)
#define UDC_SOF_EVENT() main_sof_action()
#define UDC_SUSPEND_EVENT() main_suspend_action()
#define UDC_RESUME_EVENT() main_resume_action()
#define UDC_VBUS_EVENT(b_vbus_high)
#define UDC_SOF_EVENT() main_sof_action()
#define UDC_SUSPEND_EVENT() main_suspend_action()
#define UDC_RESUME_EVENT() main_resume_action()
//! Mandatory when USB_DEVICE_ATTR authorizes remote wakeup feature
#define UDC_REMOTEWAKEUP_ENABLE() main_remotewakeup_enable()
#define UDC_REMOTEWAKEUP_DISABLE() main_remotewakeup_disable()
#define UDC_REMOTEWAKEUP_ENABLE() main_remotewakeup_enable()
#define UDC_REMOTEWAKEUP_DISABLE() main_remotewakeup_disable()
//! When a extra string descriptor must be supported
//! other than manufacturer, product and serial string
// #define UDC_GET_EXTRA_STRING()
@ -107,7 +107,6 @@
//@}
/**
* USB Interface Configuration
* @{
@ -118,42 +117,40 @@
*/
//! Interface callback definition
#ifdef KBD
#define UDI_HID_KBD_ENABLE_EXT() main_kbd_enable()
#define UDI_HID_KBD_DISABLE_EXT() main_kbd_disable()
# define UDI_HID_KBD_ENABLE_EXT() main_kbd_enable()
# define UDI_HID_KBD_DISABLE_EXT() main_kbd_disable()
//#define UDI_HID_KBD_CHANGE_LED(value) ui_kbd_led(value)
#endif
#ifdef NKRO
#define UDI_HID_NKRO_ENABLE_EXT() main_nkro_enable()
#define UDI_HID_NKRO_DISABLE_EXT() main_nkro_disable()
# define UDI_HID_NKRO_ENABLE_EXT() main_nkro_enable()
# define UDI_HID_NKRO_DISABLE_EXT() main_nkro_disable()
//#define UDI_HID_NKRO_CHANGE_LED(value) ui_kbd_led(value)
#endif
#ifdef EXK
#define UDI_HID_EXK_ENABLE_EXT() main_exk_enable()
#define UDI_HID_EXK_DISABLE_EXT() main_exk_disable()
# define UDI_HID_EXK_ENABLE_EXT() main_exk_enable()
# define UDI_HID_EXK_DISABLE_EXT() main_exk_disable()
#endif
#ifdef CON
#define UDI_HID_CON_ENABLE_EXT() main_con_enable()
#define UDI_HID_CON_DISABLE_EXT() main_con_disable()
# define UDI_HID_CON_ENABLE_EXT() main_con_enable()
# define UDI_HID_CON_DISABLE_EXT() main_con_disable()
#endif
#ifdef MOU
#define UDI_HID_MOU_ENABLE_EXT() main_mou_enable()
#define UDI_HID_MOU_DISABLE_EXT() main_mou_disable()
# define UDI_HID_MOU_ENABLE_EXT() main_mou_enable()
# define UDI_HID_MOU_DISABLE_EXT() main_mou_disable()
#endif
#ifdef RAW
#define UDI_HID_RAW_ENABLE_EXT() main_raw_enable()
#define UDI_HID_RAW_DISABLE_EXT() main_raw_disable()
# define UDI_HID_RAW_ENABLE_EXT() main_raw_enable()
# define UDI_HID_RAW_DISABLE_EXT() main_raw_disable()
#endif
//@}
//@}
/**
* USB Device Driver Configuration
* @{
@ -165,4 +162,4 @@
#include "usb_main.h"
#include "ui.h"
#endif // _CONF_USB_H_
#endif // _CONF_USB_H_

View file

@ -21,112 +21,72 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
uint8_t keyboard_protocol = 1;
void main_suspend_action(void)
{
ui_powerdown();
}
void main_suspend_action(void) { ui_powerdown(); }
void main_resume_action(void)
{
ui_wakeup();
}
void main_resume_action(void) { ui_wakeup(); }
void main_sof_action(void)
{
ui_process(udd_get_frame_number());
}
void main_sof_action(void) { ui_process(udd_get_frame_number()); }
void main_remotewakeup_enable(void)
{
ui_wakeup_enable();
}
void main_remotewakeup_enable(void) { ui_wakeup_enable(); }
void main_remotewakeup_disable(void)
{
ui_wakeup_disable();
}
void main_remotewakeup_disable(void) { ui_wakeup_disable(); }
#ifdef KBD
volatile bool main_b_kbd_enable = false;
bool main_kbd_enable(void)
{
bool main_kbd_enable(void) {
main_b_kbd_enable = true;
return true;
}
void main_kbd_disable(void)
{
main_b_kbd_enable = false;
}
void main_kbd_disable(void) { main_b_kbd_enable = false; }
#endif
#ifdef NKRO
volatile bool main_b_nkro_enable = false;
bool main_nkro_enable(void)
{
bool main_nkro_enable(void) {
main_b_nkro_enable = true;
return true;
}
void main_nkro_disable(void)
{
main_b_nkro_enable = false;
}
void main_nkro_disable(void) { main_b_nkro_enable = false; }
#endif
#ifdef EXK
volatile bool main_b_exk_enable = false;
bool main_exk_enable(void)
{
bool main_exk_enable(void) {
main_b_exk_enable = true;
return true;
}
void main_exk_disable(void)
{
main_b_exk_enable = false;
}
void main_exk_disable(void) { main_b_exk_enable = false; }
#endif
#ifdef CON
volatile bool main_b_con_enable = false;
bool main_con_enable(void)
{
bool main_con_enable(void) {
main_b_con_enable = true;
return true;
}
void main_con_disable(void)
{
main_b_con_enable = false;
}
void main_con_disable(void) { main_b_con_enable = false; }
#endif
#ifdef MOU
volatile bool main_b_mou_enable = false;
bool main_mou_enable(void)
{
bool main_mou_enable(void) {
main_b_mou_enable = true;
return true;
}
void main_mou_disable(void)
{
main_b_mou_enable = false;
}
void main_mou_disable(void) { main_b_mou_enable = false; }
#endif
#ifdef RAW
volatile bool main_b_raw_enable = false;
bool main_raw_enable(void)
{
bool main_raw_enable(void) {
main_b_raw_enable = true;
return true;
}
void main_raw_disable(void)
{
main_b_raw_enable = false;
}
void main_raw_disable(void) { main_b_raw_enable = false; }
#endif

View file

@ -61,18 +61,18 @@
*/
/** Mask to retrieve the error category of a status code. */
#define STATUS_CATEGORY_MASK 0xF0
#define STATUS_CATEGORY_MASK 0xF0
/** Mask to retrieve the error code within the category of a status code. */
#define STATUS_ERROR_MASK 0x0F
#define STATUS_ERROR_MASK 0x0F
/** Status code error categories. */
enum status_categories {
STATUS_CATEGORY_OK = 0x00,
STATUS_CATEGORY_COMMON = 0x10,
STATUS_CATEGORY_ANALOG = 0x30,
STATUS_CATEGORY_COM = 0x40,
STATUS_CATEGORY_IO = 0x50,
STATUS_CATEGORY_OK = 0x00,
STATUS_CATEGORY_COMMON = 0x10,
STATUS_CATEGORY_ANALOG = 0x30,
STATUS_CATEGORY_COM = 0x40,
STATUS_CATEGORY_IO = 0x50,
};
/**
@ -85,37 +85,37 @@ enum status_categories {
* at the same time.
*/
enum status_code {
STATUS_OK = STATUS_CATEGORY_OK | 0x00,
STATUS_VALID_DATA = STATUS_CATEGORY_OK | 0x01,
STATUS_NO_CHANGE = STATUS_CATEGORY_OK | 0x02,
STATUS_ABORTED = STATUS_CATEGORY_OK | 0x04,
STATUS_BUSY = STATUS_CATEGORY_OK | 0x05,
STATUS_SUSPEND = STATUS_CATEGORY_OK | 0x06,
STATUS_OK = STATUS_CATEGORY_OK | 0x00,
STATUS_VALID_DATA = STATUS_CATEGORY_OK | 0x01,
STATUS_NO_CHANGE = STATUS_CATEGORY_OK | 0x02,
STATUS_ABORTED = STATUS_CATEGORY_OK | 0x04,
STATUS_BUSY = STATUS_CATEGORY_OK | 0x05,
STATUS_SUSPEND = STATUS_CATEGORY_OK | 0x06,
STATUS_ERR_IO = STATUS_CATEGORY_COMMON | 0x00,
STATUS_ERR_REQ_FLUSHED = STATUS_CATEGORY_COMMON | 0x01,
STATUS_ERR_TIMEOUT = STATUS_CATEGORY_COMMON | 0x02,
STATUS_ERR_BAD_DATA = STATUS_CATEGORY_COMMON | 0x03,
STATUS_ERR_NOT_FOUND = STATUS_CATEGORY_COMMON | 0x04,
STATUS_ERR_UNSUPPORTED_DEV = STATUS_CATEGORY_COMMON | 0x05,
STATUS_ERR_NO_MEMORY = STATUS_CATEGORY_COMMON | 0x06,
STATUS_ERR_INVALID_ARG = STATUS_CATEGORY_COMMON | 0x07,
STATUS_ERR_BAD_ADDRESS = STATUS_CATEGORY_COMMON | 0x08,
STATUS_ERR_BAD_FORMAT = STATUS_CATEGORY_COMMON | 0x0A,
STATUS_ERR_BAD_FRQ = STATUS_CATEGORY_COMMON | 0x0B,
STATUS_ERR_DENIED = STATUS_CATEGORY_COMMON | 0x0c,
STATUS_ERR_ALREADY_INITIALIZED = STATUS_CATEGORY_COMMON | 0x0d,
STATUS_ERR_OVERFLOW = STATUS_CATEGORY_COMMON | 0x0e,
STATUS_ERR_NOT_INITIALIZED = STATUS_CATEGORY_COMMON | 0x0f,
STATUS_ERR_IO = STATUS_CATEGORY_COMMON | 0x00,
STATUS_ERR_REQ_FLUSHED = STATUS_CATEGORY_COMMON | 0x01,
STATUS_ERR_TIMEOUT = STATUS_CATEGORY_COMMON | 0x02,
STATUS_ERR_BAD_DATA = STATUS_CATEGORY_COMMON | 0x03,
STATUS_ERR_NOT_FOUND = STATUS_CATEGORY_COMMON | 0x04,
STATUS_ERR_UNSUPPORTED_DEV = STATUS_CATEGORY_COMMON | 0x05,
STATUS_ERR_NO_MEMORY = STATUS_CATEGORY_COMMON | 0x06,
STATUS_ERR_INVALID_ARG = STATUS_CATEGORY_COMMON | 0x07,
STATUS_ERR_BAD_ADDRESS = STATUS_CATEGORY_COMMON | 0x08,
STATUS_ERR_BAD_FORMAT = STATUS_CATEGORY_COMMON | 0x0A,
STATUS_ERR_BAD_FRQ = STATUS_CATEGORY_COMMON | 0x0B,
STATUS_ERR_DENIED = STATUS_CATEGORY_COMMON | 0x0c,
STATUS_ERR_ALREADY_INITIALIZED = STATUS_CATEGORY_COMMON | 0x0d,
STATUS_ERR_OVERFLOW = STATUS_CATEGORY_COMMON | 0x0e,
STATUS_ERR_NOT_INITIALIZED = STATUS_CATEGORY_COMMON | 0x0f,
STATUS_ERR_SAMPLERATE_UNAVAILABLE = STATUS_CATEGORY_ANALOG | 0x00,
STATUS_ERR_RESOLUTION_UNAVAILABLE = STATUS_CATEGORY_ANALOG | 0x01,
STATUS_ERR_BAUDRATE_UNAVAILABLE = STATUS_CATEGORY_COM | 0x00,
STATUS_ERR_PACKET_COLLISION = STATUS_CATEGORY_COM | 0x01,
STATUS_ERR_PROTOCOL = STATUS_CATEGORY_COM | 0x02,
STATUS_ERR_BAUDRATE_UNAVAILABLE = STATUS_CATEGORY_COM | 0x00,
STATUS_ERR_PACKET_COLLISION = STATUS_CATEGORY_COM | 0x01,
STATUS_ERR_PROTOCOL = STATUS_CATEGORY_COM | 0x02,
STATUS_ERR_PIN_MUX_INVALID = STATUS_CATEGORY_IO | 0x00,
STATUS_ERR_PIN_MUX_INVALID = STATUS_CATEGORY_IO | 0x00,
};
typedef enum status_code status_code_genare_t;
@ -123,21 +123,21 @@ typedef enum status_code status_code_genare_t;
Status codes used by MAC stack.
*/
enum status_code_wireless {
//STATUS_OK = 0, //!< Success
ERR_IO_ERROR = -1, //!< I/O error
ERR_FLUSHED = -2, //!< Request flushed from queue
ERR_TIMEOUT = -3, //!< Operation timed out
ERR_BAD_DATA = -4, //!< Data integrity check failed
ERR_PROTOCOL = -5, //!< Protocol error
ERR_UNSUPPORTED_DEV = -6, //!< Unsupported device
ERR_NO_MEMORY = -7, //!< Insufficient memory
ERR_INVALID_ARG = -8, //!< Invalid argument
ERR_BAD_ADDRESS = -9, //!< Bad address
ERR_BUSY = -10, //!< Resource is busy
ERR_BAD_FORMAT = -11, //!< Data format not recognized
ERR_NO_TIMER = -12, //!< No timer available
ERR_TIMER_ALREADY_RUNNING = -13, //!< Timer already running
ERR_TIMER_NOT_RUNNING = -14, //!< Timer not running
// STATUS_OK = 0, //!< Success
ERR_IO_ERROR = -1, //!< I/O error
ERR_FLUSHED = -2, //!< Request flushed from queue
ERR_TIMEOUT = -3, //!< Operation timed out
ERR_BAD_DATA = -4, //!< Data integrity check failed
ERR_PROTOCOL = -5, //!< Protocol error
ERR_UNSUPPORTED_DEV = -6, //!< Unsupported device
ERR_NO_MEMORY = -7, //!< Insufficient memory
ERR_INVALID_ARG = -8, //!< Invalid argument
ERR_BAD_ADDRESS = -9, //!< Bad address
ERR_BUSY = -10, //!< Resource is busy
ERR_BAD_FORMAT = -11, //!< Data format not recognized
ERR_NO_TIMER = -12, //!< No timer available
ERR_TIMER_ALREADY_RUNNING = -13, //!< Timer already running
ERR_TIMER_NOT_RUNNING = -14, //!< Timer not running
/**
* \brief Operation in progress
@ -148,7 +148,7 @@ enum status_code_wireless {
* \note Drivers should never return this status code to any
* callers. It is strictly for internal use.
*/
OPERATION_IN_PROGRESS = -128,
OPERATION_IN_PROGRESS = -128,
};
typedef enum status_code_wireless status_code_t;

File diff suppressed because it is too large Load diff

View file

@ -53,11 +53,11 @@
#include "udd.h"
#if USB_DEVICE_VENDOR_ID == 0
# error USB_DEVICE_VENDOR_ID cannot be equal to 0
# error USB_DEVICE_VENDOR_ID cannot be equal to 0
#endif
#if USB_DEVICE_PRODUCT_ID == 0
# error USB_DEVICE_PRODUCT_ID cannot be equal to 0
# error USB_DEVICE_PRODUCT_ID cannot be equal to 0
#endif
#ifdef __cplusplus
@ -172,10 +172,7 @@ extern "C" {
}
\endcode
*/
static inline bool udc_include_vbus_monitoring(void)
{
return udd_include_vbus_monitoring();
}
static inline bool udc_include_vbus_monitoring(void) { return udd_include_vbus_monitoring(); }
/*! \brief Start the USB Device stack
*/
@ -192,28 +189,19 @@ void udc_stop(void);
* then it will attach device when an acceptable Vbus
* level from the host is detected.
*/
static inline void udc_attach(void)
{
udd_attach();
}
static inline void udc_attach(void) { udd_attach(); }
/**
* \brief Detaches the device from the bus
*
* The driver must remove pull-up on USB line D- or D+.
*/
static inline void udc_detach(void)
{
udd_detach();
}
static inline void udc_detach(void) { udd_detach(); }
/*! \brief The USB driver sends a resume signal called \e "Upstream Resume"
* This is authorized only when the remote wakeup feature is enabled by host.
*/
inline void udc_remotewakeup(void)
{
udd_send_remotewakeup();
}
inline void udc_remotewakeup(void) { udd_send_remotewakeup(); }
/**
* \brief Returns a pointer on the current interface descriptor
@ -257,4 +245,4 @@ usb_iface_desc_t UDC_DESC_STORAGE *udc_get_interface_desc(void);
}
#endif
#endif // _UDC_H_
#endif // _UDC_H_

View file

@ -77,23 +77,21 @@ extern "C" {
*
* For Mega application used "code".
*/
#define UDC_DESC_STORAGE
// Descriptor storage in internal RAM
#define UDC_DESC_STORAGE
// Descriptor storage in internal RAM
#if (defined UDC_DATA_USE_HRAM_SUPPORT)
#if defined(__GNUC__)
#define UDC_DATA(x) COMPILER_WORD_ALIGNED __attribute__((__section__(".data_hram0")))
#define UDC_BSS(x) COMPILER_ALIGNED(x) __attribute__((__section__(".bss_hram0")))
#elif defined(__ICCAVR32__)
#define UDC_DATA(x) COMPILER_ALIGNED(x) __data32
#define UDC_BSS(x) COMPILER_ALIGNED(x) __data32
#endif
# if defined(__GNUC__)
# define UDC_DATA(x) COMPILER_WORD_ALIGNED __attribute__((__section__(".data_hram0")))
# define UDC_BSS(x) COMPILER_ALIGNED(x) __attribute__((__section__(".bss_hram0")))
# elif defined(__ICCAVR32__)
# define UDC_DATA(x) COMPILER_ALIGNED(x) __data32
# define UDC_BSS(x) COMPILER_ALIGNED(x) __data32
# endif
#else
#define UDC_DATA(x) COMPILER_ALIGNED(x)
#define UDC_BSS(x) COMPILER_ALIGNED(x)
# define UDC_DATA(x) COMPILER_ALIGNED(x)
# define UDC_BSS(x) COMPILER_ALIGNED(x)
#endif
/**
* \brief Configuration descriptor and UDI link for one USB speed
*/
@ -101,10 +99,9 @@ typedef struct {
//! USB configuration descriptor
usb_conf_desc_t UDC_DESC_STORAGE *desc;
//! Array of UDI API pointer
udi_api_t UDC_DESC_STORAGE *UDC_DESC_STORAGE * udi_apis;
udi_api_t UDC_DESC_STORAGE *UDC_DESC_STORAGE *udi_apis;
} udc_config_speed_t;
/**
* \brief All information about the USB Device
*/
@ -132,4 +129,4 @@ extern UDC_DESC_STORAGE udc_config_t udc_config;
#ifdef __cplusplus
}
#endif
#endif // _UDC_DESC_H_
#endif // _UDC_DESC_H_

View file

@ -71,7 +71,7 @@ typedef uint8_t udd_ep_id_t;
//! \brief Endpoint transfer status
//! Returned in parameters of callback register via udd_ep_run routine.
typedef enum {
UDD_EP_TRANSFER_OK = 0,
UDD_EP_TRANSFER_OK = 0,
UDD_EP_TRANSFER_ABORT = 1,
} udd_ep_status_t;
@ -94,36 +94,32 @@ typedef struct {
uint16_t payload_size;
//! Callback called after reception of ZLP from setup request
void (*callback) (void);
void (*callback)(void);
//! Callback called when the buffer given (.payload) is full or empty.
//! This one return false to abort data transfer, or true with a new buffer in .payload.
bool(*over_under_run) (void);
bool (*over_under_run)(void);
} udd_ctrl_request_t;
extern udd_ctrl_request_t udd_g_ctrlreq;
//! Return true if the setup request \a udd_g_ctrlreq indicates IN data transfer
#define Udd_setup_is_in() \
(USB_REQ_DIR_IN == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK))
#define Udd_setup_is_in() (USB_REQ_DIR_IN == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK))
//! Return true if the setup request \a udd_g_ctrlreq indicates OUT data transfer
#define Udd_setup_is_out() \
(USB_REQ_DIR_OUT == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK))
#define Udd_setup_is_out() (USB_REQ_DIR_OUT == (udd_g_ctrlreq.req.bmRequestType & USB_REQ_DIR_MASK))
//! Return the type of the SETUP request \a udd_g_ctrlreq. \see usb_reqtype.
#define Udd_setup_type() \
(udd_g_ctrlreq.req.bmRequestType & USB_REQ_TYPE_MASK)
#define Udd_setup_type() (udd_g_ctrlreq.req.bmRequestType & USB_REQ_TYPE_MASK)
//! Return the recipient of the SETUP request \a udd_g_ctrlreq. \see usb_recipient
#define Udd_setup_recipient() \
(udd_g_ctrlreq.req.bmRequestType & USB_REQ_RECIP_MASK)
#define Udd_setup_recipient() (udd_g_ctrlreq.req.bmRequestType & USB_REQ_RECIP_MASK)
/**
* \brief End of halt callback function type.
* Registered by routine udd_ep_wait_stall_clear()
* Callback called when endpoint stall is cleared.
*/
typedef void (*udd_callback_halt_cleared_t) (void);
typedef void (*udd_callback_halt_cleared_t)(void);
/**
* \brief End of transfer callback function type.
@ -134,8 +130,7 @@ typedef void (*udd_callback_halt_cleared_t) (void);
* \param status UDD_EP_TRANSFER_ABORT, if transfer is aborted
* \param n number of data transfered
*/
typedef void (*udd_callback_trans_t) (udd_ep_status_t status,
iram_size_t nb_transfered, udd_ep_id_t ep);
typedef void (*udd_callback_trans_t)(udd_ep_status_t status, iram_size_t nb_transfered, udd_ep_id_t ep);
/**
* \brief Authorizes the VBUS event
@ -216,8 +211,7 @@ void udd_send_remotewakeup(void);
* \param payload Pointer on payload
* \param payload_size Size of payload
*/
void udd_set_setup_payload( uint8_t *payload, uint16_t payload_size );
void udd_set_setup_payload(uint8_t *payload, uint16_t payload_size);
/**
* \name Endpoint Management
@ -239,8 +233,7 @@ void udd_set_setup_payload( uint8_t *payload, uint16_t payload_size );
*
* \return \c 1 if the endpoint is enabled, otherwise \c 0.
*/
bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes,
uint16_t MaxEndpointSize);
bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize);
/**
* \brief Disables an endpoint
@ -294,8 +287,7 @@ bool udd_ep_clear_halt(udd_ep_id_t ep);
*
* \return \c 1 if the register is accepted, otherwise \c 0.
*/
bool udd_ep_wait_stall_clear(udd_ep_id_t ep,
udd_callback_halt_cleared_t callback);
bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callback);
/**
* \brief Allows to receive or send data on an endpoint
@ -321,9 +313,7 @@ bool udd_ep_wait_stall_clear(udd_ep_id_t ep,
*
* \return \c 1 if function was successfully done, otherwise \c 0.
*/
bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket,
uint8_t *buf, iram_size_t buf_size,
udd_callback_trans_t callback);
bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback);
/**
* \brief Aborts transfer on going on endpoint
*
@ -339,7 +329,6 @@ void udd_ep_abort(udd_ep_id_t ep);
//@}
/**
* \name High speed test mode management
*
@ -352,7 +341,6 @@ void udd_test_mode_se0_nak(void);
void udd_test_mode_packet(void);
//@}
/**
* \name UDC callbacks to provide for UDD
*
@ -393,4 +381,4 @@ extern void udc_sof_notify(void);
#ifdef __cplusplus
}
#endif
#endif // _UDD_H_
#endif // _UDD_H_

View file

@ -72,57 +72,57 @@ extern "C" {
* selected by UDC.
*/
typedef struct {
/**
* \brief Enable the interface.
*
* This function is called when the host selects a configuration
* to which this interface belongs through a Set Configuration
* request, and when the host selects an alternate setting of
* this interface through a Set Interface request.
*
* \return \c 1 if function was successfully done, otherwise \c 0.
*/
bool(*enable) (void);
/**
* \brief Enable the interface.
*
* This function is called when the host selects a configuration
* to which this interface belongs through a Set Configuration
* request, and when the host selects an alternate setting of
* this interface through a Set Interface request.
*
* \return \c 1 if function was successfully done, otherwise \c 0.
*/
bool (*enable)(void);
/**
* \brief Disable the interface.
*
* This function is called when this interface is currently
* active, and
* - the host selects any configuration through a Set
* Configuration request, or
* - the host issues a USB reset, or
* - the device is detached from the host (i.e. Vbus is no
* longer present)
*/
void (*disable) (void);
/**
* \brief Disable the interface.
*
* This function is called when this interface is currently
* active, and
* - the host selects any configuration through a Set
* Configuration request, or
* - the host issues a USB reset, or
* - the device is detached from the host (i.e. Vbus is no
* longer present)
*/
void (*disable)(void);
/**
* \brief Handle a control request directed at an interface.
*
* This function is called when this interface is currently
* active and the host sends a SETUP request
* with this interface as the recipient.
*
* Use udd_g_ctrlreq to decode and response to SETUP request.
*
* \return \c 1 if this interface supports the SETUP request, otherwise \c 0.
*/
bool(*setup) (void);
/**
* \brief Handle a control request directed at an interface.
*
* This function is called when this interface is currently
* active and the host sends a SETUP request
* with this interface as the recipient.
*
* Use udd_g_ctrlreq to decode and response to SETUP request.
*
* \return \c 1 if this interface supports the SETUP request, otherwise \c 0.
*/
bool (*setup)(void);
/**
* \brief Returns the current setting of the selected interface.
*
* This function is called when UDC when know alternate setting of selected interface.
*
* \return alternate setting of selected interface
*/
uint8_t(*getsetting) (void);
/**
* \brief Returns the current setting of the selected interface.
*
* This function is called when UDC when know alternate setting of selected interface.
*
* \return alternate setting of selected interface
*/
uint8_t (*getsetting)(void);
/**
* \brief To signal that a SOF is occurred
*/
void(*sof_notify) (void);
/**
* \brief To signal that a SOF is occurred
*/
void (*sof_notify)(void);
} udi_api_t;
//@}
@ -130,4 +130,4 @@ typedef struct {
#ifdef __cplusplus
}
#endif
#endif // _UDI_H_
#endif // _UDI_H_

File diff suppressed because it is too large Load diff

View file

@ -49,24 +49,24 @@
#ifdef CDC
#include "conf_usb.h"
#include "usb_protocol.h"
#include "usb_protocol_cdc.h"
#include "udd.h"
#include "udc_desc.h"
#include "udi.h"
# include "conf_usb.h"
# include "usb_protocol.h"
# include "usb_protocol_cdc.h"
# include "udd.h"
# include "udc_desc.h"
# include "udi.h"
// Check the number of port
#ifndef UDI_CDC_PORT_NB
# define UDI_CDC_PORT_NB 1
#endif
#if (UDI_CDC_PORT_NB > 1)
# error UDI_CDC_PORT_NB must be at most 1
#endif
# ifndef UDI_CDC_PORT_NB
# define UDI_CDC_PORT_NB 1
# endif
# if (UDI_CDC_PORT_NB > 1)
# error UDI_CDC_PORT_NB must be at most 1
# endif
#ifdef __cplusplus
# ifdef __cplusplus
extern "C" {
#endif
# endif
/**
* \addtogroup udi_cdc_group_udc
@ -82,9 +82,9 @@ extern UDC_DESC_STORAGE udi_api_t udi_api_cdc_data;
//#define CDC_RX_SIZE 64
//! CDC communication endpoints size for all speeds
#define UDI_CDC_COMM_EP_SIZE CDC_ACM_SIZE
# define UDI_CDC_COMM_EP_SIZE CDC_ACM_SIZE
//! CDC data endpoints size for FS speed (8B, 16B, 32B, 64B)
#define UDI_CDC_DATA_EPS_FS_SIZE CDC_RX_SIZE
# define UDI_CDC_DATA_EPS_FS_SIZE CDC_RX_SIZE
//@}
@ -335,42 +335,42 @@ int udi_cdc_multi_putc(uint8_t port, int value);
iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t size);
//@}
#define CDC_PRINTBUF_SIZE 256
# define CDC_PRINTBUF_SIZE 256
extern char printbuf[CDC_PRINTBUF_SIZE];
#define CDC_INBUF_SIZE 256
# define CDC_INBUF_SIZE 256
typedef struct {
uint32_t count;
uint32_t lastcount;
char buf[CDC_INBUF_SIZE];
char buf[CDC_INBUF_SIZE];
} inbuf_t;
#else //CDC
#else // CDC
// keep these to accommodate calls if remaining
#define CDC_PRINTBUF_SIZE 1
# define CDC_PRINTBUF_SIZE 1
extern char printbuf[CDC_PRINTBUF_SIZE];
#define CDC_INBUF_SIZE 1
# define CDC_INBUF_SIZE 1
typedef struct {
uint32_t count;
uint32_t lastcount;
char buf[CDC_INBUF_SIZE];
char buf[CDC_INBUF_SIZE];
} inbuf_t;
extern inbuf_t inbuf;
#endif //CDC
#endif // CDC
uint32_t CDC_print(char *printbuf);
int CDC_printf(const char *_Format, ...);
uint32_t CDC_print(char* printbuf);
int CDC_printf(const char* _Format, ...);
uint32_t CDC_input(void);
void CDC_init(void);
void CDC_init(void);
#ifdef __cplusplus
}
#endif
#endif // _UDI_CDC_H_
#endif // _UDI_CDC_H_

View file

@ -51,22 +51,22 @@
#include "conf_usb.h"
#include "udi_device_conf.h"
#ifndef UDI_CDC_PORT_NB
#define UDI_CDC_PORT_NB 1
#ifndef UDI_CDC_PORT_NB
# define UDI_CDC_PORT_NB 1
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define UDI_CDC_DATA_EP_IN_0 ((CDC_TX_ENDPOINT) | (USB_EP_DIR_IN)) //TX
#define UDI_CDC_DATA_EP_OUT_0 ((CDC_RX_ENDPOINT) | (USB_EP_DIR_OUT)) // RX
#define UDI_CDC_COMM_EP_0 ((CDC_ACM_ENDPOINT) | (USB_EP_DIR_IN)) // Notify endpoint
#define UDI_CDC_DATA_EP_IN_0 ((CDC_TX_ENDPOINT) | (USB_EP_DIR_IN)) // TX
#define UDI_CDC_DATA_EP_OUT_0 ((CDC_RX_ENDPOINT) | (USB_EP_DIR_OUT)) // RX
#define UDI_CDC_COMM_EP_0 ((CDC_ACM_ENDPOINT) | (USB_EP_DIR_IN)) // Notify endpoint
#define UDI_CDC_COMM_IFACE_NUMBER_0 (CDC_STATUS_INTERFACE)
#define UDI_CDC_DATA_IFACE_NUMBER_0 (CDC_DATA_INTERFACE)
#define UDI_CDC_COMM_IFACE_NUMBER_0 (CDC_STATUS_INTERFACE)
#define UDI_CDC_DATA_IFACE_NUMBER_0 (CDC_DATA_INTERFACE)
#ifdef __cplusplus
}
#endif
#endif // _UDI_CDC_CONF_H_
#endif // _UDI_CDC_CONF_H_

View file

@ -31,27 +31,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define MOUSE_ENABLE //rules.mk
#ifdef MOUSE_ENABLE
#define MOU
# define MOU
#endif
//#define EXTRAKEY_ENABLE //rules.mk
#ifdef EXTRAKEY_ENABLE
#define EXK
# define EXK
#endif
//#define RAW_ENABLE //rules.mk
#ifdef RAW_ENABLE
#define RAW
# define RAW
#endif
//#define CONSOLE_ENABLE //rules.mk
#ifdef CONSOLE_ENABLE
#define CON
# define CON
#endif
//#define NKRO_ENABLE //rules.mk
#ifdef NKRO_ENABLE
#define NKRO
# define NKRO
#endif
//#define MIDI_ENABLE //deferred implementation
@ -61,229 +61,227 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define VIRTSER_ENABLE //rules.mk
#ifdef VIRTSER_ENABLE
#define CDC
//because CDC uses IAD (interface association descriptor
//per USB Interface Association Descriptor Device Class Code and Use Model 7/23/2003 Rev 1.0)
#undef DEVICE_CLASS
#define DEVICE_CLASS 0xEF
#undef DEVICE_SUBCLASS
#define DEVICE_SUBCLASS 0x02
#undef DEVICE_PROTOCOL
#define DEVICE_PROTOCOL 0x01
# define CDC
// because CDC uses IAD (interface association descriptor
// per USB Interface Association Descriptor Device Class Code and Use Model 7/23/2003 Rev 1.0)
# undef DEVICE_CLASS
# define DEVICE_CLASS 0xEF
# undef DEVICE_SUBCLASS
# define DEVICE_SUBCLASS 0x02
# undef DEVICE_PROTOCOL
# define DEVICE_PROTOCOL 0x01
#endif
/* number of interfaces */
#define NEXT_INTERFACE_0 0
#define NEXT_INTERFACE_0 0
#ifdef KBD
#define KEYBOARD_INTERFACE NEXT_INTERFACE_0
#define NEXT_INTERFACE_1 (KEYBOARD_INTERFACE + 1)
#define UDI_HID_KBD_IFACE_NUMBER KEYBOARD_INTERFACE
# define KEYBOARD_INTERFACE NEXT_INTERFACE_0
# define NEXT_INTERFACE_1 (KEYBOARD_INTERFACE + 1)
# define UDI_HID_KBD_IFACE_NUMBER KEYBOARD_INTERFACE
#else
#define NEXT_INTERFACE_1 NEXT_INTERFACE_0
# define NEXT_INTERFACE_1 NEXT_INTERFACE_0
#endif
// It is important that the Raw HID interface is at a constant
// interface number, to support Linux/OSX platforms and chrome.hid
// If Raw HID is enabled, let it be always 1.
#ifdef RAW
#define RAW_INTERFACE NEXT_INTERFACE_1
#define NEXT_INTERFACE_2 (RAW_INTERFACE + 1)
# define RAW_INTERFACE NEXT_INTERFACE_1
# define NEXT_INTERFACE_2 (RAW_INTERFACE + 1)
#else
#define NEXT_INTERFACE_2 NEXT_INTERFACE_1
# define NEXT_INTERFACE_2 NEXT_INTERFACE_1
#endif
#ifdef MOU
#define MOUSE_INTERFACE NEXT_INTERFACE_2
#define UDI_HID_MOU_IFACE_NUMBER MOUSE_INTERFACE
#define NEXT_INTERFACE_3 (MOUSE_INTERFACE + 1)
# define MOUSE_INTERFACE NEXT_INTERFACE_2
# define UDI_HID_MOU_IFACE_NUMBER MOUSE_INTERFACE
# define NEXT_INTERFACE_3 (MOUSE_INTERFACE + 1)
#else
#define NEXT_INTERFACE_3 NEXT_INTERFACE_2
# define NEXT_INTERFACE_3 NEXT_INTERFACE_2
#endif
#ifdef EXK
#define EXTRAKEY_INTERFACE NEXT_INTERFACE_3
#define NEXT_INTERFACE_4 (EXTRAKEY_INTERFACE + 1)
#define UDI_HID_EXK_IFACE_NUMBER EXTRAKEY_INTERFACE
# define EXTRAKEY_INTERFACE NEXT_INTERFACE_3
# define NEXT_INTERFACE_4 (EXTRAKEY_INTERFACE + 1)
# define UDI_HID_EXK_IFACE_NUMBER EXTRAKEY_INTERFACE
#else
#define NEXT_INTERFACE_4 NEXT_INTERFACE_3
# define NEXT_INTERFACE_4 NEXT_INTERFACE_3
#endif
#ifdef CON
#define CON_INTERFACE NEXT_INTERFACE_4
#define NEXT_INTERFACE_5 (CON_INTERFACE + 1)
#define UDI_HID_CON_IFACE_NUMBER CON_INTERFACE
# define CON_INTERFACE NEXT_INTERFACE_4
# define NEXT_INTERFACE_5 (CON_INTERFACE + 1)
# define UDI_HID_CON_IFACE_NUMBER CON_INTERFACE
#else
#define NEXT_INTERFACE_5 NEXT_INTERFACE_4
# define NEXT_INTERFACE_5 NEXT_INTERFACE_4
#endif
#ifdef NKRO
#define NKRO_INTERFACE NEXT_INTERFACE_5
#define NEXT_INTERFACE_6 (NKRO_INTERFACE + 1)
#define UDI_HID_NKRO_IFACE_NUMBER NKRO_INTERFACE
# define NKRO_INTERFACE NEXT_INTERFACE_5
# define NEXT_INTERFACE_6 (NKRO_INTERFACE + 1)
# define UDI_HID_NKRO_IFACE_NUMBER NKRO_INTERFACE
#else
#define NEXT_INTERFACE_6 NEXT_INTERFACE_5
# define NEXT_INTERFACE_6 NEXT_INTERFACE_5
#endif
#ifdef MIDI
#define AC_INTERFACE NEXT_INTERFACE_6
#define AS_INTERFACE (AC_INTERFACE + 1)
#define NEXT_INTERFACE_7 (AS_INTERFACE + 1)
# define AC_INTERFACE NEXT_INTERFACE_6
# define AS_INTERFACE (AC_INTERFACE + 1)
# define NEXT_INTERFACE_7 (AS_INTERFACE + 1)
#else
#define NEXT_INTERFACE_7 NEXT_INTERFACE_6
# define NEXT_INTERFACE_7 NEXT_INTERFACE_6
#endif
#ifdef CDC
#define CCI_INTERFACE NEXT_INTERFACE_7
#define CDI_INTERFACE (CCI_INTERFACE + 1)
#define NEXT_INTERFACE_8 (CDI_INTERFACE + 1)
#define CDC_STATUS_INTERFACE CCI_INTERFACE
#define CDC_DATA_INTERFACE CDI_INTERFACE
# define CCI_INTERFACE NEXT_INTERFACE_7
# define CDI_INTERFACE (CCI_INTERFACE + 1)
# define NEXT_INTERFACE_8 (CDI_INTERFACE + 1)
# define CDC_STATUS_INTERFACE CCI_INTERFACE
# define CDC_DATA_INTERFACE CDI_INTERFACE
#else
#define NEXT_INTERFACE_8 NEXT_INTERFACE_7
# define NEXT_INTERFACE_8 NEXT_INTERFACE_7
#endif
/* nubmer of interfaces */
#define TOTAL_INTERFACES NEXT_INTERFACE_8
#define USB_DEVICE_NB_INTERFACE TOTAL_INTERFACES
#define TOTAL_INTERFACES NEXT_INTERFACE_8
#define USB_DEVICE_NB_INTERFACE TOTAL_INTERFACES
// **********************************************************************
// Endopoint number and size
// **********************************************************************
#define USB_DEVICE_EP_CTRL_SIZE 8
#define USB_DEVICE_EP_CTRL_SIZE 8
#define NEXT_IN_EPNUM_0 1
#define NEXT_OUT_EPNUM_0 1
#define NEXT_IN_EPNUM_0 1
#define NEXT_OUT_EPNUM_0 1
#ifdef KBD
#define KEYBOARD_IN_EPNUM NEXT_IN_EPNUM_0
#define UDI_HID_KBD_EP_IN KEYBOARD_IN_EPNUM
#define NEXT_IN_EPNUM_1 (KEYBOARD_IN_EPNUM + 1)
#define UDI_HID_KBD_EP_SIZE KEYBOARD_EPSIZE
#define KBD_POLLING_INTERVAL 10
#ifndef UDI_HID_KBD_STRING_ID
#define UDI_HID_KBD_STRING_ID 0
#endif
# define KEYBOARD_IN_EPNUM NEXT_IN_EPNUM_0
# define UDI_HID_KBD_EP_IN KEYBOARD_IN_EPNUM
# define NEXT_IN_EPNUM_1 (KEYBOARD_IN_EPNUM + 1)
# define UDI_HID_KBD_EP_SIZE KEYBOARD_EPSIZE
# define KBD_POLLING_INTERVAL 10
# ifndef UDI_HID_KBD_STRING_ID
# define UDI_HID_KBD_STRING_ID 0
# endif
#else
#define NEXT_IN_EPNUM_1 NEXT_IN_EPNUM_0
# define NEXT_IN_EPNUM_1 NEXT_IN_EPNUM_0
#endif
#ifdef MOU
#define MOUSE_IN_EPNUM NEXT_IN_EPNUM_1
#define NEXT_IN_EPNUM_2 (MOUSE_IN_EPNUM + 1)
#define UDI_HID_MOU_EP_IN MOUSE_IN_EPNUM
#define UDI_HID_MOU_EP_SIZE MOUSE_EPSIZE
#define MOU_POLLING_INTERVAL 10
#ifndef UDI_HID_MOU_STRING_ID
#define UDI_HID_MOU_STRING_ID 0
#endif
# define MOUSE_IN_EPNUM NEXT_IN_EPNUM_1
# define NEXT_IN_EPNUM_2 (MOUSE_IN_EPNUM + 1)
# define UDI_HID_MOU_EP_IN MOUSE_IN_EPNUM
# define UDI_HID_MOU_EP_SIZE MOUSE_EPSIZE
# define MOU_POLLING_INTERVAL 10
# ifndef UDI_HID_MOU_STRING_ID
# define UDI_HID_MOU_STRING_ID 0
# endif
#else
#define NEXT_IN_EPNUM_2 NEXT_IN_EPNUM_1
# define NEXT_IN_EPNUM_2 NEXT_IN_EPNUM_1
#endif
#ifdef EXK
#define EXTRAKEY_IN_EPNUM NEXT_IN_EPNUM_2
#define UDI_HID_EXK_EP_IN EXTRAKEY_IN_EPNUM
#define NEXT_IN_EPNUM_3 (EXTRAKEY_IN_EPNUM + 1)
#define UDI_HID_EXK_EP_SIZE EXTRAKEY_EPSIZE
#define EXTRAKEY_POLLING_INTERVAL 10
#ifndef UDI_HID_EXK_STRING_ID
#define UDI_HID_EXK_STRING_ID 0
#endif
# define EXTRAKEY_IN_EPNUM NEXT_IN_EPNUM_2
# define UDI_HID_EXK_EP_IN EXTRAKEY_IN_EPNUM
# define NEXT_IN_EPNUM_3 (EXTRAKEY_IN_EPNUM + 1)
# define UDI_HID_EXK_EP_SIZE EXTRAKEY_EPSIZE
# define EXTRAKEY_POLLING_INTERVAL 10
# ifndef UDI_HID_EXK_STRING_ID
# define UDI_HID_EXK_STRING_ID 0
# endif
#else
#define NEXT_IN_EPNUM_3 NEXT_IN_EPNUM_2
# define NEXT_IN_EPNUM_3 NEXT_IN_EPNUM_2
#endif
#ifdef RAW
#define RAW_IN_EPNUM NEXT_IN_EPNUM_3
#define UDI_HID_RAW_EP_IN RAW_IN_EPNUM
#define NEXT_IN_EPNUM_4 (RAW_IN_EPNUM + 1)
#define RAW_OUT_EPNUM NEXT_OUT_EPNUM_0
#define UDI_HID_RAW_EP_OUT RAW_OUT_EPNUM
#define NEXT_OUT_EPNUM_1 (RAW_OUT_EPNUM + 1)
#define RAW_POLLING_INTERVAL 1
#ifndef UDI_HID_RAW_STRING_ID
#define UDI_HID_RAW_STRING_ID 0
#endif
# define RAW_IN_EPNUM NEXT_IN_EPNUM_3
# define UDI_HID_RAW_EP_IN RAW_IN_EPNUM
# define NEXT_IN_EPNUM_4 (RAW_IN_EPNUM + 1)
# define RAW_OUT_EPNUM NEXT_OUT_EPNUM_0
# define UDI_HID_RAW_EP_OUT RAW_OUT_EPNUM
# define NEXT_OUT_EPNUM_1 (RAW_OUT_EPNUM + 1)
# define RAW_POLLING_INTERVAL 1
# ifndef UDI_HID_RAW_STRING_ID
# define UDI_HID_RAW_STRING_ID 0
# endif
#else
#define NEXT_IN_EPNUM_4 NEXT_IN_EPNUM_3
#define NEXT_OUT_EPNUM_1 NEXT_OUT_EPNUM_0
# define NEXT_IN_EPNUM_4 NEXT_IN_EPNUM_3
# define NEXT_OUT_EPNUM_1 NEXT_OUT_EPNUM_0
#endif
#ifdef CON
#define CON_IN_EPNUM NEXT_IN_EPNUM_4
#define UDI_HID_CON_EP_IN CON_IN_EPNUM
#define NEXT_IN_EPNUM_5 (CON_IN_EPNUM + 1)
#define CON_OUT_EPNUM NEXT_OUT_EPNUM_1
#define UDI_HID_CON_EP_OUT CON_OUT_EPNUM
#define NEXT_OUT_EPNUM_2 (CON_OUT_EPNUM + 1)
#define CON_POLLING_INTERVAL 1
#ifndef UDI_HID_CON_STRING_ID
#define UDI_HID_CON_STRING_ID 0
#endif
# define CON_IN_EPNUM NEXT_IN_EPNUM_4
# define UDI_HID_CON_EP_IN CON_IN_EPNUM
# define NEXT_IN_EPNUM_5 (CON_IN_EPNUM + 1)
# define CON_OUT_EPNUM NEXT_OUT_EPNUM_1
# define UDI_HID_CON_EP_OUT CON_OUT_EPNUM
# define NEXT_OUT_EPNUM_2 (CON_OUT_EPNUM + 1)
# define CON_POLLING_INTERVAL 1
# ifndef UDI_HID_CON_STRING_ID
# define UDI_HID_CON_STRING_ID 0
# endif
#else
#define NEXT_IN_EPNUM_5 NEXT_IN_EPNUM_4
#define NEXT_OUT_EPNUM_2 NEXT_OUT_EPNUM_1
# define NEXT_IN_EPNUM_5 NEXT_IN_EPNUM_4
# define NEXT_OUT_EPNUM_2 NEXT_OUT_EPNUM_1
#endif
#ifdef NKRO
#define NKRO_IN_EPNUM NEXT_IN_EPNUM_5
#define UDI_HID_NKRO_EP_IN NKRO_IN_EPNUM
#define NEXT_IN_EPNUM_6 (NKRO_IN_EPNUM + 1)
#define UDI_HID_NKRO_EP_SIZE NKRO_EPSIZE
#define NKRO_POLLING_INTERVAL 1
#ifndef UDI_HID_NKRO_STRING_ID
#define UDI_HID_NKRO_STRING_ID 0
#endif
# define NKRO_IN_EPNUM NEXT_IN_EPNUM_5
# define UDI_HID_NKRO_EP_IN NKRO_IN_EPNUM
# define NEXT_IN_EPNUM_6 (NKRO_IN_EPNUM + 1)
# define UDI_HID_NKRO_EP_SIZE NKRO_EPSIZE
# define NKRO_POLLING_INTERVAL 1
# ifndef UDI_HID_NKRO_STRING_ID
# define UDI_HID_NKRO_STRING_ID 0
# endif
#else
#define NEXT_IN_EPNUM_6 NEXT_IN_EPNUM_5
# define NEXT_IN_EPNUM_6 NEXT_IN_EPNUM_5
#endif
#ifdef MIDI
#define MIDI_STREAM_IN_EPNUM NEXT_IN_EPNUM_6
#define NEXT_IN_EPNUM_7 (MIDI_STREAM_IN_EPNUM + 1)
#define MIDI_STREAM_OUT_EPNUM NEXT_OUT_EPNUM_2
#define NEXT_OUT_EPNUM_3 (MIDI_STREAM_OUT_EPNUM + 1)
#define MIDI_POLLING_INTERVAL 5
# define MIDI_STREAM_IN_EPNUM NEXT_IN_EPNUM_6
# define NEXT_IN_EPNUM_7 (MIDI_STREAM_IN_EPNUM + 1)
# define MIDI_STREAM_OUT_EPNUM NEXT_OUT_EPNUM_2
# define NEXT_OUT_EPNUM_3 (MIDI_STREAM_OUT_EPNUM + 1)
# define MIDI_POLLING_INTERVAL 5
#else
#define NEXT_IN_EPNUM_7 NEXT_IN_EPNUM_6
#define NEXT_OUT_EPNUM_3 NEXT_OUT_EPNUM_2
# define NEXT_IN_EPNUM_7 NEXT_IN_EPNUM_6
# define NEXT_OUT_EPNUM_3 NEXT_OUT_EPNUM_2
#endif
#ifdef CDC
#define CDC_NOTIFICATION_EPNUM NEXT_IN_EPNUM_7
#define CDC_ACM_ENDPOINT CDC_NOTIFICATION_EPNUM
#define CDC_TX_ENDPOINT (CDC_NOTIFICATION_EPNUM + 1)
#define NEXT_IN_EPNUM_8 (CDC_TX_ENDPOINT + 1)
# define CDC_NOTIFICATION_EPNUM NEXT_IN_EPNUM_7
# define CDC_ACM_ENDPOINT CDC_NOTIFICATION_EPNUM
# define CDC_TX_ENDPOINT (CDC_NOTIFICATION_EPNUM + 1)
# define NEXT_IN_EPNUM_8 (CDC_TX_ENDPOINT + 1)
#define CDC_OUT_EPNUM NEXT_OUT_EPNUM_3
#define CDC_RX_ENDPOINT CDC_OUT_EPNUM
#define NEXT_OUT_EPNUM_4 (CDC_OUT_EPNUM + 1)
# define CDC_OUT_EPNUM NEXT_OUT_EPNUM_3
# define CDC_RX_ENDPOINT CDC_OUT_EPNUM
# define NEXT_OUT_EPNUM_4 (CDC_OUT_EPNUM + 1)
#define CDC_ACM_SIZE CDC_NOTIFICATION_EPSIZE
#define CDC_RX_SIZE CDC_EPSIZE //KFSMOD was 64
#define CDC_TX_SIZE CDC_RX_SIZE
#define CDC_ACM_POLLING_INTERVAL 255
#define CDC_EP_INTERVAL_STATUS CDC_ACM_POLLING_INTERVAL
#define CDC_DATA_POLLING_INTERVAL 5
#define CDC_EP_INTERVAL_DATA CDC_DATA_POLLING_INTERVAL
#define CDC_STATUS_NAME L"Virtual Serial Port - Status"
#define CDC_DATA_NAME L"Virtual Serial Port - Data"
# define CDC_ACM_SIZE CDC_NOTIFICATION_EPSIZE
# define CDC_RX_SIZE CDC_EPSIZE // KFSMOD was 64
# define CDC_TX_SIZE CDC_RX_SIZE
# define CDC_ACM_POLLING_INTERVAL 255
# define CDC_EP_INTERVAL_STATUS CDC_ACM_POLLING_INTERVAL
# define CDC_DATA_POLLING_INTERVAL 5
# define CDC_EP_INTERVAL_DATA CDC_DATA_POLLING_INTERVAL
# define CDC_STATUS_NAME L"Virtual Serial Port - Status"
# define CDC_DATA_NAME L"Virtual Serial Port - Data"
#else
#define NEXT_IN_EPNUM_8 NEXT_IN_EPNUM_7
#define NEXT_OUT_EPNUM_4 NEXT_OUT_EPNUM_3
# define NEXT_IN_EPNUM_8 NEXT_IN_EPNUM_7
# define NEXT_OUT_EPNUM_4 NEXT_OUT_EPNUM_3
#endif
#define TOTAL_OUT_EP NEXT_OUT_EPNUM_4
#define TOTAL_IN_EP NEXT_IN_EPNUM_8
#define USB_DEVICE_MAX_EP (max(NEXT_OUT_EPNUM_4, NEXT_IN_EPNUM_8))
#define TOTAL_OUT_EP NEXT_OUT_EPNUM_4
#define TOTAL_IN_EP NEXT_IN_EPNUM_8
#define USB_DEVICE_MAX_EP (max(NEXT_OUT_EPNUM_4, NEXT_IN_EPNUM_8))
#if USB_DEVICE_MAX_EP > 8
#error "There are not enough available endpoints to support all functions. Remove some in the rules.mk file.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, VIRTSER)"
# error "There are not enough available endpoints to support all functions. Remove some in the rules.mk file.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, VIRTSER)"
#endif
// **********************************************************************
// KBD Descriptor structure and content
// **********************************************************************
@ -292,50 +290,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
COMPILER_PACK_SET(1)
typedef struct {
usb_iface_desc_t iface;
usb_iface_desc_t iface;
usb_hid_descriptor_t hid;
usb_ep_desc_t ep;
usb_ep_desc_t ep;
} udi_hid_kbd_desc_t;
typedef struct {
uint8_t array[59];
} udi_hid_kbd_report_desc_t;
#define UDI_HID_KBD_DESC {\
.iface.bLength = sizeof(usb_iface_desc_t),\
.iface.bDescriptorType = USB_DT_INTERFACE,\
.iface.bInterfaceNumber = UDI_HID_KBD_IFACE_NUMBER,\
.iface.bAlternateSetting = 0,\
.iface.bNumEndpoints = 1,\
.iface.bInterfaceClass = HID_CLASS,\
.iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT,\
.iface.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,\
.iface.iInterface = UDI_HID_KBD_STRING_ID,\
.hid.bLength = sizeof(usb_hid_descriptor_t),\
.hid.bDescriptorType = USB_DT_HID,\
.hid.bcdHID = LE16(USB_HID_BDC_V1_11),\
.hid.bCountryCode = USB_HID_NO_COUNTRY_CODE,\
.hid.bNumDescriptors = USB_HID_NUM_DESC,\
.hid.bRDescriptorType = USB_DT_HID_REPORT,\
.hid.wDescriptorLength = LE16(sizeof(udi_hid_kbd_report_desc_t)),\
.ep.bLength = sizeof(usb_ep_desc_t),\
.ep.bDescriptorType = USB_DT_ENDPOINT,\
.ep.bEndpointAddress = UDI_HID_KBD_EP_IN | USB_EP_DIR_IN,\
.ep.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep.wMaxPacketSize = LE16(UDI_HID_KBD_EP_SIZE),\
.ep.bInterval = KBD_POLLING_INTERVAL,\
}
# define UDI_HID_KBD_DESC \
{ .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = UDI_HID_KBD_IFACE_NUMBER, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 1, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT, .iface.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD, .iface.iInterface = UDI_HID_KBD_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_kbd_report_desc_t)), .ep.bLength = sizeof(usb_ep_desc_t), .ep.bDescriptorType = USB_DT_ENDPOINT, .ep.bEndpointAddress = UDI_HID_KBD_EP_IN | USB_EP_DIR_IN, .ep.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep.wMaxPacketSize = LE16(UDI_HID_KBD_EP_SIZE), .ep.bInterval = KBD_POLLING_INTERVAL, }
//set report buffer (from host)
// set report buffer (from host)
extern uint8_t udi_hid_kbd_report_set;
//report buffer (to host)
#define UDI_HID_KBD_REPORT_SIZE 8
// report buffer (to host)
# define UDI_HID_KBD_REPORT_SIZE 8
extern uint8_t udi_hid_kbd_report[UDI_HID_KBD_REPORT_SIZE];
COMPILER_PACK_RESET()
#endif //KBD
#endif // KBD
// **********************************************************************
// EXK Descriptor structure and content
@ -345,59 +321,37 @@ COMPILER_PACK_RESET()
COMPILER_PACK_SET(1)
typedef struct {
usb_iface_desc_t iface;
usb_iface_desc_t iface;
usb_hid_descriptor_t hid;
usb_ep_desc_t ep;
usb_ep_desc_t ep;
} udi_hid_exk_desc_t;
typedef struct {
uint8_t array[54];
} udi_hid_exk_report_desc_t;
#define UDI_HID_EXK_DESC {\
.iface.bLength = sizeof(usb_iface_desc_t),\
.iface.bDescriptorType = USB_DT_INTERFACE,\
.iface.bInterfaceNumber = UDI_HID_EXK_IFACE_NUMBER,\
.iface.bAlternateSetting = 0,\
.iface.bNumEndpoints = 1,\
.iface.bInterfaceClass = HID_CLASS,\
.iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT,\
.iface.bInterfaceProtocol = HID_PROTOCOL_GENERIC,\
.iface.iInterface = UDI_HID_EXK_STRING_ID,\
.hid.bLength = sizeof(usb_hid_descriptor_t),\
.hid.bDescriptorType = USB_DT_HID,\
.hid.bcdHID = LE16(USB_HID_BDC_V1_11),\
.hid.bCountryCode = USB_HID_NO_COUNTRY_CODE,\
.hid.bNumDescriptors = USB_HID_NUM_DESC,\
.hid.bRDescriptorType = USB_DT_HID_REPORT,\
.hid.wDescriptorLength = LE16(sizeof(udi_hid_exk_report_desc_t)),\
.ep.bLength = sizeof(usb_ep_desc_t),\
.ep.bDescriptorType = USB_DT_ENDPOINT,\
.ep.bEndpointAddress = UDI_HID_EXK_EP_IN | USB_EP_DIR_IN,\
.ep.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep.wMaxPacketSize = LE16(UDI_HID_EXK_EP_SIZE),\
.ep.bInterval = EXTRAKEY_POLLING_INTERVAL,\
}
# define UDI_HID_EXK_DESC \
{ .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = UDI_HID_EXK_IFACE_NUMBER, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 1, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT, .iface.bInterfaceProtocol = HID_PROTOCOL_GENERIC, .iface.iInterface = UDI_HID_EXK_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_exk_report_desc_t)), .ep.bLength = sizeof(usb_ep_desc_t), .ep.bDescriptorType = USB_DT_ENDPOINT, .ep.bEndpointAddress = UDI_HID_EXK_EP_IN | USB_EP_DIR_IN, .ep.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep.wMaxPacketSize = LE16(UDI_HID_EXK_EP_SIZE), .ep.bInterval = EXTRAKEY_POLLING_INTERVAL, }
//set report buffer (from host)
// set report buffer (from host)
extern uint8_t udi_hid_exk_report_set;
//report buffer
#define UDI_HID_EXK_REPORT_SIZE 3
// report buffer
# define UDI_HID_EXK_REPORT_SIZE 3
typedef union {
struct {
uint8_t report_id;
uint16_t report_data;
} desc;
uint8_t raw[UDI_HID_EXK_REPORT_SIZE];
struct {
uint8_t report_id;
uint16_t report_data;
} desc;
uint8_t raw[UDI_HID_EXK_REPORT_SIZE];
} udi_hid_exk_report_t;
extern udi_hid_exk_report_t udi_hid_exk_report;
COMPILER_PACK_RESET()
#endif //EXK
#endif // EXK
// **********************************************************************
// NKRO Descriptor structure and content
@ -407,50 +361,28 @@ COMPILER_PACK_RESET()
COMPILER_PACK_SET(1)
typedef struct {
usb_iface_desc_t iface;
usb_iface_desc_t iface;
usb_hid_descriptor_t hid;
usb_ep_desc_t ep;
usb_ep_desc_t ep;
} udi_hid_nkro_desc_t;
typedef struct {
uint8_t array[57];
} udi_hid_nkro_report_desc_t;
#define UDI_HID_NKRO_DESC {\
.iface.bLength = sizeof(usb_iface_desc_t),\
.iface.bDescriptorType = USB_DT_INTERFACE,\
.iface.bInterfaceNumber = UDI_HID_NKRO_IFACE_NUMBER,\
.iface.bAlternateSetting = 0,\
.iface.bNumEndpoints = 1,\
.iface.bInterfaceClass = HID_CLASS,\
.iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT,\
.iface.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,\
.iface.iInterface = UDI_HID_NKRO_STRING_ID,\
.hid.bLength = sizeof(usb_hid_descriptor_t),\
.hid.bDescriptorType = USB_DT_HID,\
.hid.bcdHID = LE16(USB_HID_BDC_V1_11),\
.hid.bCountryCode = USB_HID_NO_COUNTRY_CODE,\
.hid.bNumDescriptors = USB_HID_NUM_DESC,\
.hid.bRDescriptorType = USB_DT_HID_REPORT,\
.hid.wDescriptorLength = LE16(sizeof(udi_hid_nkro_report_desc_t)),\
.ep.bLength = sizeof(usb_ep_desc_t),\
.ep.bDescriptorType = USB_DT_ENDPOINT,\
.ep.bEndpointAddress = UDI_HID_NKRO_EP_IN | USB_EP_DIR_IN,\
.ep.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep.wMaxPacketSize = LE16(UDI_HID_NKRO_EP_SIZE),\
.ep.bInterval = NKRO_POLLING_INTERVAL,\
}
# define UDI_HID_NKRO_DESC \
{ .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = UDI_HID_NKRO_IFACE_NUMBER, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 1, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT, .iface.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD, .iface.iInterface = UDI_HID_NKRO_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_nkro_report_desc_t)), .ep.bLength = sizeof(usb_ep_desc_t), .ep.bDescriptorType = USB_DT_ENDPOINT, .ep.bEndpointAddress = UDI_HID_NKRO_EP_IN | USB_EP_DIR_IN, .ep.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep.wMaxPacketSize = LE16(UDI_HID_NKRO_EP_SIZE), .ep.bInterval = NKRO_POLLING_INTERVAL, }
//set report buffer
// set report buffer
extern uint8_t udi_hid_nkro_report_set;
//report buffer
#define UDI_HID_NKRO_REPORT_SIZE 32
// report buffer
# define UDI_HID_NKRO_REPORT_SIZE 32
extern uint8_t udi_hid_nkro_report[UDI_HID_NKRO_REPORT_SIZE];
COMPILER_PACK_RESET()
#endif //NKRO
#endif // NKRO
// **********************************************************************
// MOU Descriptor structure and content
@ -460,49 +392,27 @@ COMPILER_PACK_RESET()
COMPILER_PACK_SET(1)
typedef struct {
usb_iface_desc_t iface;
usb_iface_desc_t iface;
usb_hid_descriptor_t hid;
usb_ep_desc_t ep;
usb_ep_desc_t ep;
} udi_hid_mou_desc_t;
typedef struct {
uint8_t array[77];//MOU PDS
uint8_t array[77]; // MOU PDS
} udi_hid_mou_report_desc_t;
#define UDI_HID_MOU_DESC {\
.iface.bLength = sizeof(usb_iface_desc_t),\
.iface.bDescriptorType = USB_DT_INTERFACE,\
.iface.bInterfaceNumber = MOUSE_INTERFACE,\
.iface.bAlternateSetting = 0,\
.iface.bNumEndpoints = 1,\
.iface.bInterfaceClass = HID_CLASS,\
.iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT,\
.iface.bInterfaceProtocol = HID_PROTOCOL_MOUSE,\
.iface.iInterface = UDI_HID_MOU_STRING_ID,\
.hid.bLength = sizeof(usb_hid_descriptor_t),\
.hid.bDescriptorType = USB_DT_HID,\
.hid.bcdHID = LE16(USB_HID_BDC_V1_11),\
.hid.bCountryCode = USB_HID_NO_COUNTRY_CODE,\
.hid.bNumDescriptors = USB_HID_NUM_DESC,\
.hid.bRDescriptorType = USB_DT_HID_REPORT,\
.hid.wDescriptorLength = LE16(sizeof(udi_hid_mou_report_desc_t)),\
.ep.bLength = sizeof(usb_ep_desc_t),\
.ep.bDescriptorType = USB_DT_ENDPOINT,\
.ep.bEndpointAddress = UDI_HID_MOU_EP_IN | USB_EP_DIR_IN,\
.ep.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep.wMaxPacketSize = LE16(UDI_HID_MOU_EP_SIZE),\
.ep.bInterval = MOU_POLLING_INTERVAL,\
}
# define UDI_HID_MOU_DESC \
{ .iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = MOUSE_INTERFACE, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 1, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_BOOT, .iface.bInterfaceProtocol = HID_PROTOCOL_MOUSE, .iface.iInterface = UDI_HID_MOU_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_mou_report_desc_t)), .ep.bLength = sizeof(usb_ep_desc_t), .ep.bDescriptorType = USB_DT_ENDPOINT, .ep.bEndpointAddress = UDI_HID_MOU_EP_IN | USB_EP_DIR_IN, .ep.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep.wMaxPacketSize = LE16(UDI_HID_MOU_EP_SIZE), .ep.bInterval = MOU_POLLING_INTERVAL, }
//no set report buffer
// no set report buffer
//report buffer
#define UDI_HID_MOU_REPORT_SIZE 5 //MOU PDS
// report buffer
# define UDI_HID_MOU_REPORT_SIZE 5 // MOU PDS
extern uint8_t udi_hid_mou_report[UDI_HID_MOU_REPORT_SIZE];
COMPILER_PACK_RESET()
#endif //MOU
#endif // MOU
// **********************************************************************
// RAW Descriptor structure and content
@ -512,57 +422,32 @@ COMPILER_PACK_RESET()
COMPILER_PACK_SET(1)
typedef struct {
usb_iface_desc_t iface;
usb_iface_desc_t iface;
usb_hid_descriptor_t hid;
usb_ep_desc_t ep_out;
usb_ep_desc_t ep_in;
usb_ep_desc_t ep_out;
usb_ep_desc_t ep_in;
} udi_hid_raw_desc_t;
typedef struct {
uint8_t array[27];
} udi_hid_raw_report_desc_t;
#define UDI_HID_RAW_DESC {\
.iface.bLength = sizeof(usb_iface_desc_t),\
.iface.bDescriptorType = USB_DT_INTERFACE,\
.iface.bInterfaceNumber = RAW_INTERFACE,\
.iface.bAlternateSetting = 0,\
.iface.bNumEndpoints = 2,\
.iface.bInterfaceClass = HID_CLASS,\
.iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT,\
.iface.bInterfaceProtocol = HID_SUB_CLASS_NOBOOT,\
.iface.iInterface = UDI_HID_RAW_STRING_ID,\
.hid.bLength = sizeof(usb_hid_descriptor_t),\
.hid.bDescriptorType = USB_DT_HID,\
.hid.bcdHID = LE16(USB_HID_BDC_V1_11),\
.hid.bCountryCode = USB_HID_NO_COUNTRY_CODE,\
.hid.bNumDescriptors = USB_HID_NUM_DESC,\
.hid.bRDescriptorType = USB_DT_HID_REPORT,\
.hid.wDescriptorLength = LE16(sizeof(udi_hid_raw_report_desc_t)),\
.ep_out.bLength = sizeof(usb_ep_desc_t),\
.ep_out.bDescriptorType = USB_DT_ENDPOINT,\
.ep_out.bEndpointAddress = UDI_HID_RAW_EP_OUT | USB_EP_DIR_OUT,\
.ep_out.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep_out.wMaxPacketSize = LE16(RAW_EPSIZE),\
.ep_out.bInterval = RAW_POLLING_INTERVAL,\
.ep_in.bLength = sizeof(usb_ep_desc_t),\
.ep_in.bDescriptorType = USB_DT_ENDPOINT,\
.ep_in.bEndpointAddress = UDI_HID_RAW_EP_IN | USB_EP_DIR_IN,\
.ep_in.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep_in.wMaxPacketSize = LE16(RAW_EPSIZE),\
.ep_in.bInterval = RAW_POLLING_INTERVAL,\
}
# define UDI_HID_RAW_DESC \
{ \
.iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = RAW_INTERFACE, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 2, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT, .iface.bInterfaceProtocol = HID_SUB_CLASS_NOBOOT, .iface.iInterface = UDI_HID_RAW_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_raw_report_desc_t)), .ep_out.bLength = sizeof(usb_ep_desc_t), .ep_out.bDescriptorType = USB_DT_ENDPOINT, .ep_out.bEndpointAddress = UDI_HID_RAW_EP_OUT | USB_EP_DIR_OUT, .ep_out.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_out.wMaxPacketSize = LE16(RAW_EPSIZE), .ep_out.bInterval = RAW_POLLING_INTERVAL, \
.ep_in.bLength = sizeof(usb_ep_desc_t), .ep_in.bDescriptorType = USB_DT_ENDPOINT, .ep_in.bEndpointAddress = UDI_HID_RAW_EP_IN | USB_EP_DIR_IN, .ep_in.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_in.wMaxPacketSize = LE16(RAW_EPSIZE), .ep_in.bInterval = RAW_POLLING_INTERVAL, \
}
#define UDI_HID_RAW_REPORT_SIZE RAW_EPSIZE
# define UDI_HID_RAW_REPORT_SIZE RAW_EPSIZE
extern uint8_t udi_hid_raw_report_set[UDI_HID_RAW_REPORT_SIZE];
//report buffer
// report buffer
extern uint8_t udi_hid_raw_report[UDI_HID_RAW_REPORT_SIZE];
COMPILER_PACK_RESET()
#endif //RAW
#endif // RAW
// **********************************************************************
// CON Descriptor structure and content
@ -572,57 +457,32 @@ COMPILER_PACK_RESET()
COMPILER_PACK_SET(1)
typedef struct {
usb_iface_desc_t iface;
usb_iface_desc_t iface;
usb_hid_descriptor_t hid;
usb_ep_desc_t ep_out;
usb_ep_desc_t ep_in;
usb_ep_desc_t ep_out;
usb_ep_desc_t ep_in;
} udi_hid_con_desc_t;
typedef struct {
uint8_t array[34];
} udi_hid_con_report_desc_t;
#define UDI_HID_CON_DESC {\
.iface.bLength = sizeof(usb_iface_desc_t),\
.iface.bDescriptorType = USB_DT_INTERFACE,\
.iface.bInterfaceNumber = UDI_HID_CON_IFACE_NUMBER,\
.iface.bAlternateSetting = 0,\
.iface.bNumEndpoints = 2,\
.iface.bInterfaceClass = HID_CLASS,\
.iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT,\
.iface.bInterfaceProtocol = HID_SUB_CLASS_NOBOOT,\
.iface.iInterface = UDI_HID_CON_STRING_ID,\
.hid.bLength = sizeof(usb_hid_descriptor_t),\
.hid.bDescriptorType = USB_DT_HID,\
.hid.bcdHID = LE16(USB_HID_BDC_V1_11),\
.hid.bCountryCode = USB_HID_NO_COUNTRY_CODE,\
.hid.bNumDescriptors = USB_HID_NUM_DESC,\
.hid.bRDescriptorType = USB_DT_HID_REPORT,\
.hid.wDescriptorLength = LE16(sizeof(udi_hid_con_report_desc_t)),\
.ep_out.bLength = sizeof(usb_ep_desc_t),\
.ep_out.bDescriptorType = USB_DT_ENDPOINT,\
.ep_out.bEndpointAddress = UDI_HID_CON_EP_OUT | USB_EP_DIR_OUT,\
.ep_out.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep_out.wMaxPacketSize = LE16(CONSOLE_EPSIZE),\
.ep_out.bInterval = CON_POLLING_INTERVAL,\
.ep_in.bLength = sizeof(usb_ep_desc_t),\
.ep_in.bDescriptorType = USB_DT_ENDPOINT,\
.ep_in.bEndpointAddress = UDI_HID_CON_EP_IN | USB_EP_DIR_IN,\
.ep_in.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep_in.wMaxPacketSize = LE16(CONSOLE_EPSIZE),\
.ep_in.bInterval = CON_POLLING_INTERVAL,\
}
# define UDI_HID_CON_DESC \
{ \
.iface.bLength = sizeof(usb_iface_desc_t), .iface.bDescriptorType = USB_DT_INTERFACE, .iface.bInterfaceNumber = UDI_HID_CON_IFACE_NUMBER, .iface.bAlternateSetting = 0, .iface.bNumEndpoints = 2, .iface.bInterfaceClass = HID_CLASS, .iface.bInterfaceSubClass = HID_SUB_CLASS_NOBOOT, .iface.bInterfaceProtocol = HID_SUB_CLASS_NOBOOT, .iface.iInterface = UDI_HID_CON_STRING_ID, .hid.bLength = sizeof(usb_hid_descriptor_t), .hid.bDescriptorType = USB_DT_HID, .hid.bcdHID = LE16(USB_HID_BDC_V1_11), .hid.bCountryCode = USB_HID_NO_COUNTRY_CODE, .hid.bNumDescriptors = USB_HID_NUM_DESC, .hid.bRDescriptorType = USB_DT_HID_REPORT, .hid.wDescriptorLength = LE16(sizeof(udi_hid_con_report_desc_t)), .ep_out.bLength = sizeof(usb_ep_desc_t), .ep_out.bDescriptorType = USB_DT_ENDPOINT, .ep_out.bEndpointAddress = UDI_HID_CON_EP_OUT | USB_EP_DIR_OUT, .ep_out.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_out.wMaxPacketSize = LE16(CONSOLE_EPSIZE), .ep_out.bInterval = CON_POLLING_INTERVAL, \
.ep_in.bLength = sizeof(usb_ep_desc_t), .ep_in.bDescriptorType = USB_DT_ENDPOINT, .ep_in.bEndpointAddress = UDI_HID_CON_EP_IN | USB_EP_DIR_IN, .ep_in.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_in.wMaxPacketSize = LE16(CONSOLE_EPSIZE), .ep_in.bInterval = CON_POLLING_INTERVAL, \
}
#define UDI_HID_CON_REPORT_SIZE CONSOLE_EPSIZE
# define UDI_HID_CON_REPORT_SIZE CONSOLE_EPSIZE
extern uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
//report buffer
// report buffer
extern uint8_t udi_hid_con_report[UDI_HID_CON_REPORT_SIZE];
COMPILER_PACK_RESET()
#endif //CON
#endif // CON
// **********************************************************************
// CDC Descriptor structure and content
@ -662,86 +522,28 @@ typedef struct {
} usb_cdc_union_desc_t;
typedef struct {
usb_association_desc_t iaface;
usb_iface_desc_t iface_c;
usb_cdc_hdr_desc_t fd;
usb_association_desc_t iaface;
usb_iface_desc_t iface_c;
usb_cdc_hdr_desc_t fd;
usb_cdc_call_mgmt_desc_t mfd;
usb_cdc_acm_desc_t acmd;
usb_cdc_union_desc_t ufd;
usb_ep_desc_t ep_c;
usb_iface_desc_t iface_d;
usb_ep_desc_t ep_tx;
usb_ep_desc_t ep_rx;
usb_cdc_acm_desc_t acmd;
usb_cdc_union_desc_t ufd;
usb_ep_desc_t ep_c;
usb_iface_desc_t iface_d;
usb_ep_desc_t ep_tx;
usb_ep_desc_t ep_rx;
} udi_cdc_desc_t;
#define CDC_DESCRIPTOR {\
.iaface.bLength = sizeof(usb_association_desc_t),\
.iaface.bDescriptorType = USB_DT_IAD,\
.iaface.bFirstInterface = CDC_STATUS_INTERFACE,\
.iaface.bInterfaceCount = 2,\
.iaface.bFunctionClass = CDC_CLASS_DEVICE,\
.iaface.bFunctionSubClass = CDC_SUBCLASS_ACM,\
.iaface.bFunctionProtocol = CDC_PROTOCOL_V25TER,\
.iaface.iFunction = 0,\
.iface_c.bLength = sizeof(usb_iface_desc_t),\
.iface_c.bDescriptorType = USB_DT_INTERFACE,\
.iface_c.bInterfaceNumber = CDC_STATUS_INTERFACE,\
.iface_c.bAlternateSetting = 0,\
.iface_c.bNumEndpoints = 1,\
.iface_c.bInterfaceClass = 0x02,\
.iface_c.bInterfaceSubClass = 0x02,\
.iface_c.bInterfaceProtocol = CDC_PROTOCOL_V25TER,\
.iface_c.iInterface = 0,\
.fd.bFunctionLength = sizeof(usb_cdc_hdr_desc_t),\
.fd.bDescriptorType = CDC_CS_INTERFACE,\
.fd.bDescriptorSubtype = CDC_SCS_HEADER,\
.fd.bcdCDC = 0x0110,\
.mfd.bFunctionLength = sizeof(usb_cdc_call_mgmt_desc_t),\
.mfd.bDescriptorType = CDC_CS_INTERFACE,\
.mfd.bDescriptorSubtype = CDC_SCS_CALL_MGMT,\
.mfd.bmCapabilities = CDC_CALL_MGMT_SUPPORTED,\
.mfd.bDataInterface = CDC_DATA_INTERFACE,\
.acmd.bFunctionLength = sizeof(usb_cdc_acm_desc_t),\
.acmd.bDescriptorType = CDC_CS_INTERFACE,\
.acmd.bDescriptorSubtype = CDC_SCS_ACM,\
.acmd.bmCapabilities = CDC_ACM_SUPPORT_LINE_REQUESTS,\
.ufd.bFunctionLength = sizeof(usb_cdc_union_desc_t),\
.ufd.bDescriptorType = CDC_CS_INTERFACE,\
.ufd.bDescriptorSubtype = CDC_SCS_UNION,\
.ufd.bMasterInterface = CDC_STATUS_INTERFACE,\
.ufd.bSlaveInterface0 = CDC_DATA_INTERFACE,\
.ep_c.bLength = sizeof(usb_ep_desc_t),\
.ep_c.bDescriptorType = USB_DT_ENDPOINT,\
.ep_c.bEndpointAddress = CDC_ACM_ENDPOINT | USB_EP_DIR_IN,\
.ep_c.bmAttributes = USB_EP_TYPE_INTERRUPT,\
.ep_c.wMaxPacketSize = LE16(CDC_ACM_SIZE),\
.ep_c.bInterval = CDC_EP_INTERVAL_STATUS,\
.iface_d.bLength = sizeof(usb_iface_desc_t),\
.iface_d.bDescriptorType = USB_DT_INTERFACE,\
.iface_d.bInterfaceNumber = CDC_DATA_INTERFACE,\
.iface_d.bAlternateSetting = 0,\
.iface_d.bNumEndpoints = 2,\
.iface_d.bInterfaceClass = CDC_CLASS_DATA,\
.iface_d.bInterfaceSubClass = 0,\
.iface_d.bInterfaceProtocol = 0,\
.iface_d.iInterface = 0,\
.ep_rx.bLength = sizeof(usb_ep_desc_t),\
.ep_rx.bDescriptorType = USB_DT_ENDPOINT,\
.ep_rx.bEndpointAddress = CDC_RX_ENDPOINT | USB_EP_DIR_OUT,\
.ep_rx.bmAttributes = USB_EP_TYPE_BULK,\
.ep_rx.wMaxPacketSize = LE16(CDC_RX_SIZE),\
.ep_rx.bInterval = CDC_EP_INTERVAL_DATA,\
.ep_tx.bLength = sizeof(usb_ep_desc_t),\
.ep_tx.bDescriptorType = USB_DT_ENDPOINT,\
.ep_tx.bEndpointAddress = CDC_TX_ENDPOINT | USB_EP_DIR_IN,\
.ep_tx.bmAttributes = USB_EP_TYPE_BULK,\
.ep_tx.wMaxPacketSize = LE16(CDC_TX_SIZE),\
.ep_tx.bInterval = CDC_EP_INTERVAL_DATA,\
}
# define CDC_DESCRIPTOR \
{ \
.iaface.bLength = sizeof(usb_association_desc_t), .iaface.bDescriptorType = USB_DT_IAD, .iaface.bFirstInterface = CDC_STATUS_INTERFACE, .iaface.bInterfaceCount = 2, .iaface.bFunctionClass = CDC_CLASS_DEVICE, .iaface.bFunctionSubClass = CDC_SUBCLASS_ACM, .iaface.bFunctionProtocol = CDC_PROTOCOL_V25TER, .iaface.iFunction = 0, .iface_c.bLength = sizeof(usb_iface_desc_t), .iface_c.bDescriptorType = USB_DT_INTERFACE, .iface_c.bInterfaceNumber = CDC_STATUS_INTERFACE, .iface_c.bAlternateSetting = 0, .iface_c.bNumEndpoints = 1, .iface_c.bInterfaceClass = 0x02, .iface_c.bInterfaceSubClass = 0x02, .iface_c.bInterfaceProtocol = CDC_PROTOCOL_V25TER, .iface_c.iInterface = 0, .fd.bFunctionLength = sizeof(usb_cdc_hdr_desc_t), .fd.bDescriptorType = CDC_CS_INTERFACE, .fd.bDescriptorSubtype = CDC_SCS_HEADER, .fd.bcdCDC = 0x0110, .mfd.bFunctionLength = sizeof(usb_cdc_call_mgmt_desc_t), .mfd.bDescriptorType = CDC_CS_INTERFACE, .mfd.bDescriptorSubtype = CDC_SCS_CALL_MGMT, \
.mfd.bmCapabilities = CDC_CALL_MGMT_SUPPORTED, .mfd.bDataInterface = CDC_DATA_INTERFACE, .acmd.bFunctionLength = sizeof(usb_cdc_acm_desc_t), .acmd.bDescriptorType = CDC_CS_INTERFACE, .acmd.bDescriptorSubtype = CDC_SCS_ACM, .acmd.bmCapabilities = CDC_ACM_SUPPORT_LINE_REQUESTS, .ufd.bFunctionLength = sizeof(usb_cdc_union_desc_t), .ufd.bDescriptorType = CDC_CS_INTERFACE, .ufd.bDescriptorSubtype = CDC_SCS_UNION, .ufd.bMasterInterface = CDC_STATUS_INTERFACE, .ufd.bSlaveInterface0 = CDC_DATA_INTERFACE, .ep_c.bLength = sizeof(usb_ep_desc_t), .ep_c.bDescriptorType = USB_DT_ENDPOINT, .ep_c.bEndpointAddress = CDC_ACM_ENDPOINT | USB_EP_DIR_IN, .ep_c.bmAttributes = USB_EP_TYPE_INTERRUPT, .ep_c.wMaxPacketSize = LE16(CDC_ACM_SIZE), .ep_c.bInterval = CDC_EP_INTERVAL_STATUS, .iface_d.bLength = sizeof(usb_iface_desc_t), .iface_d.bDescriptorType = USB_DT_INTERFACE, .iface_d.bInterfaceNumber = CDC_DATA_INTERFACE, .iface_d.bAlternateSetting = 0, .iface_d.bNumEndpoints = 2, \
.iface_d.bInterfaceClass = CDC_CLASS_DATA, .iface_d.bInterfaceSubClass = 0, .iface_d.bInterfaceProtocol = 0, .iface_d.iInterface = 0, .ep_rx.bLength = sizeof(usb_ep_desc_t), .ep_rx.bDescriptorType = USB_DT_ENDPOINT, .ep_rx.bEndpointAddress = CDC_RX_ENDPOINT | USB_EP_DIR_OUT, .ep_rx.bmAttributes = USB_EP_TYPE_BULK, .ep_rx.wMaxPacketSize = LE16(CDC_RX_SIZE), .ep_rx.bInterval = CDC_EP_INTERVAL_DATA, .ep_tx.bLength = sizeof(usb_ep_desc_t), .ep_tx.bDescriptorType = USB_DT_ENDPOINT, .ep_tx.bEndpointAddress = CDC_TX_ENDPOINT | USB_EP_DIR_IN, .ep_tx.bmAttributes = USB_EP_TYPE_BULK, .ep_tx.wMaxPacketSize = LE16(CDC_TX_SIZE), .ep_tx.bInterval = CDC_EP_INTERVAL_DATA, \
}
COMPILER_PACK_RESET()
#endif //CDC
#endif // CDC
// **********************************************************************
// CONFIGURATION Descriptor structure and content
@ -778,4 +580,4 @@ typedef struct {
COMPILER_PACK_RESET()
#endif //_UDI_DEVICE_CONF_H_
#endif //_UDI_DEVICE_CONF_H_

View file

@ -18,15 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _UDI_DEVICE_EPSIZE_H_
#define _UDI_DEVICE_EPSIZE_H_
#define KEYBOARD_EPSIZE 8
#define MOUSE_EPSIZE 8
#define EXTRAKEY_EPSIZE 8
#define RAW_EPSIZE 64
#define CONSOLE_EPSIZE 32
#define NKRO_EPSIZE 32
#define MIDI_STREAM_EPSIZE 64
#define CDC_NOTIFICATION_EPSIZE 8
#define CDC_EPSIZE 16
#endif //_UDI_DEVICE_EPSIZE_H_
#define KEYBOARD_EPSIZE 8
#define MOUSE_EPSIZE 8
#define EXTRAKEY_EPSIZE 8
#define RAW_EPSIZE 64
#define CONSOLE_EPSIZE 32
#define NKRO_EPSIZE 32
#define MIDI_STREAM_EPSIZE 64
#define CDC_NOTIFICATION_EPSIZE 8
#define CDC_EPSIZE 16
#endif //_UDI_DEVICE_EPSIZE_H_

View file

@ -50,7 +50,6 @@
#include "udc.h"
#include "udi_hid.h"
/**
* \ingroup udi_hid_group
* \defgroup udi_hid_group_internal Implementation of HID common library
@ -64,34 +63,31 @@
*/
static bool udi_hid_reqstdifaceget_descriptor(uint8_t *report_desc);
bool udi_hid_setup( uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool (*setup_report)(void) )
{
bool udi_hid_setup(uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool (*setup_report)(void)) {
if (Udd_setup_is_in()) {
// Requests Interface GET
if (Udd_setup_type() == USB_REQ_TYPE_STANDARD) {
// Requests Standard Interface Get
switch (udd_g_ctrlreq.req.bRequest) {
case USB_REQ_GET_DESCRIPTOR:
return udi_hid_reqstdifaceget_descriptor(report_desc);
case USB_REQ_GET_DESCRIPTOR:
return udi_hid_reqstdifaceget_descriptor(report_desc);
}
}
if (Udd_setup_type() == USB_REQ_TYPE_CLASS) {
// Requests Class Interface Get
switch (udd_g_ctrlreq.req.bRequest) {
case USB_REQ_HID_GET_REPORT:
return setup_report();
case USB_REQ_HID_GET_REPORT:
return setup_report();
case USB_REQ_HID_GET_IDLE:
udd_g_ctrlreq.payload = rate;
udd_g_ctrlreq.payload_size = 1;
return true;
case USB_REQ_HID_GET_IDLE:
udd_g_ctrlreq.payload = rate;
udd_g_ctrlreq.payload_size = 1;
return true;
case USB_REQ_HID_GET_PROTOCOL:
udd_g_ctrlreq.payload = protocol;
udd_g_ctrlreq.payload_size = 1;
return true;
case USB_REQ_HID_GET_PROTOCOL:
udd_g_ctrlreq.payload = protocol;
udd_g_ctrlreq.payload_size = 1;
return true;
}
}
}
@ -100,60 +96,50 @@ bool udi_hid_setup( uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool
if (Udd_setup_type() == USB_REQ_TYPE_CLASS) {
// Requests Class Interface Set
switch (udd_g_ctrlreq.req.bRequest) {
case USB_REQ_HID_SET_REPORT:
return setup_report();
case USB_REQ_HID_SET_REPORT:
return setup_report();
case USB_REQ_HID_SET_IDLE:
*rate = udd_g_ctrlreq.req.wValue >> 8;
return true;
case USB_REQ_HID_SET_IDLE:
*rate = udd_g_ctrlreq.req.wValue >> 8;
return true;
case USB_REQ_HID_SET_PROTOCOL:
if (0 != udd_g_ctrlreq.req.wLength)
return false;
*protocol = udd_g_ctrlreq.req.wValue;
return true;
case USB_REQ_HID_SET_PROTOCOL:
if (0 != udd_g_ctrlreq.req.wLength) return false;
*protocol = udd_g_ctrlreq.req.wValue;
return true;
}
}
}
return false; // Request not supported
return false; // Request not supported
}
//---------------------------------------------
//------- Internal routines
static bool udi_hid_reqstdifaceget_descriptor(uint8_t *report_desc)
{
static bool udi_hid_reqstdifaceget_descriptor(uint8_t *report_desc) {
usb_hid_descriptor_t UDC_DESC_STORAGE *ptr_hid_desc;
// Get the USB descriptor which is located after the interface descriptor
// This descriptor must be the HID descriptor
ptr_hid_desc = (usb_hid_descriptor_t UDC_DESC_STORAGE *) ((uint8_t *)
udc_get_interface_desc() + sizeof(usb_iface_desc_t));
if (USB_DT_HID != ptr_hid_desc->bDescriptorType)
return false;
ptr_hid_desc = (usb_hid_descriptor_t UDC_DESC_STORAGE *)((uint8_t *)udc_get_interface_desc() + sizeof(usb_iface_desc_t));
if (USB_DT_HID != ptr_hid_desc->bDescriptorType) return false;
// The SETUP request can ask for:
// - an USB_DT_HID descriptor
// - or USB_DT_HID_REPORT descriptor
// - or USB_DT_HID_PHYSICAL descriptor
if (USB_DT_HID == (uint8_t) (udd_g_ctrlreq.req.wValue >> 8)) {
if (USB_DT_HID == (uint8_t)(udd_g_ctrlreq.req.wValue >> 8)) {
// USB_DT_HID descriptor requested then send it
udd_g_ctrlreq.payload = (uint8_t *) ptr_hid_desc;
udd_g_ctrlreq.payload_size =
min(udd_g_ctrlreq.req.wLength,
ptr_hid_desc->bLength);
udd_g_ctrlreq.payload = (uint8_t *)ptr_hid_desc;
udd_g_ctrlreq.payload_size = min(udd_g_ctrlreq.req.wLength, ptr_hid_desc->bLength);
return true;
}
// The HID_X descriptor requested must correspond to report type
// included in the HID descriptor
if (ptr_hid_desc->bRDescriptorType ==
(uint8_t) (udd_g_ctrlreq.req.wValue >> 8)) {
if (ptr_hid_desc->bRDescriptorType == (uint8_t)(udd_g_ctrlreq.req.wValue >> 8)) {
// Send HID Report descriptor given by high level
udd_g_ctrlreq.payload = report_desc;
udd_g_ctrlreq.payload_size =
min(udd_g_ctrlreq.req.wLength,
le16_to_cpu(ptr_hid_desc->wDescriptorLength));
udd_g_ctrlreq.payload = report_desc;
udd_g_ctrlreq.payload_size = min(udd_g_ctrlreq.req.wLength, le16_to_cpu(ptr_hid_desc->wDescriptorLength));
return true;
}
return false;

View file

@ -75,11 +75,11 @@ extern "C" {
*
* \return \c 1 if function was successfully done, otherwise \c 0.
*/
bool udi_hid_setup( uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool (*setup_report)(void) );
bool udi_hid_setup(uint8_t *rate, uint8_t *protocol, uint8_t *report_desc, bool (*setup_report)(void));
//@}
#ifdef __cplusplus
}
#endif
#endif // _UDI_HID_H_
#endif // _UDI_HID_H_

File diff suppressed because it is too large Load diff

View file

@ -59,59 +59,59 @@ extern "C" {
//******************************************************************************
#ifdef KBD
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_kbd;
extern bool udi_hid_kbd_b_report_valid;
extern volatile bool udi_hid_kbd_b_report_trans_ongoing;
extern uint8_t udi_hid_kbd_report_set;
bool udi_hid_kbd_send_report(void);
#endif //KBD
extern bool udi_hid_kbd_b_report_valid;
extern volatile bool udi_hid_kbd_b_report_trans_ongoing;
extern uint8_t udi_hid_kbd_report_set;
bool udi_hid_kbd_send_report(void);
#endif // KBD
//********************************************************************************************
// NKRO Keyboard
//********************************************************************************************
#ifdef NKRO
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_nkro;
extern bool udi_hid_nkro_b_report_valid;
extern volatile bool udi_hid_nkro_b_report_trans_ongoing;
bool udi_hid_nkro_send_report(void);
#endif //NKRO
extern bool udi_hid_nkro_b_report_valid;
extern volatile bool udi_hid_nkro_b_report_trans_ongoing;
bool udi_hid_nkro_send_report(void);
#endif // NKRO
//********************************************************************************************
// SYS-CTRL interface
//********************************************************************************************
#ifdef EXK
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_exk;
extern bool udi_hid_exk_b_report_valid;
extern uint8_t udi_hid_exk_report_set;
bool udi_hid_exk_send_report(void);
#endif //EXK
extern bool udi_hid_exk_b_report_valid;
extern uint8_t udi_hid_exk_report_set;
bool udi_hid_exk_send_report(void);
#endif // EXK
//********************************************************************************************
// CON Console
//********************************************************************************************
#ifdef CON
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_con;
extern bool udi_hid_con_b_report_valid;
extern uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
extern volatile bool udi_hid_con_b_report_trans_ongoing;
bool udi_hid_con_send_report(void);
#endif //CON
extern bool udi_hid_con_b_report_valid;
extern uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
extern volatile bool udi_hid_con_b_report_trans_ongoing;
bool udi_hid_con_send_report(void);
#endif // CON
//********************************************************************************************
// MOU Mouse
//********************************************************************************************
#ifdef MOU
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_mou;
extern bool udi_hid_mou_b_report_valid;
bool udi_hid_mou_send_report(void);
#endif //MOU
extern bool udi_hid_mou_b_report_valid;
bool udi_hid_mou_send_report(void);
#endif // MOU
//********************************************************************************************
// RAW Raw
//********************************************************************************************
#ifdef RAW
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_raw;
bool udi_hid_raw_send_report(void);
#endif //RAW
bool udi_hid_raw_send_report(void);
#endif // RAW
//@}
@ -119,4 +119,4 @@ bool udi_hid_raw_send_report(void);
}
#endif
#endif // _UDC_HID_KBD_H_
#endif // _UDC_HID_KBD_H_

View file

@ -57,4 +57,4 @@
#include "udi_hid_kbd.h"
#endif // _UDI_HID_KBD_CONF_H_
#endif // _UDI_HID_KBD_CONF_H_

View file

@ -65,37 +65,35 @@
//! USB Device Descriptor
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE usb_dev_desc_t udc_device_desc = {
.bLength = sizeof(usb_dev_desc_t),
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = LE16(USB_V2_0),
.bDeviceClass = DEVICE_CLASS,
.bDeviceSubClass = DEVICE_SUBCLASS,
.bDeviceProtocol = DEVICE_PROTOCOL,
.bMaxPacketSize0 = USB_DEVICE_EP_CTRL_SIZE,
.idVendor = LE16(USB_DEVICE_VENDOR_ID),
.idProduct = LE16(USB_DEVICE_PRODUCT_ID),
.bcdDevice = LE16(USB_DEVICE_VERSION),
UDC_DESC_STORAGE usb_dev_desc_t udc_device_desc = {.bLength = sizeof(usb_dev_desc_t),
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = LE16(USB_V2_0),
.bDeviceClass = DEVICE_CLASS,
.bDeviceSubClass = DEVICE_SUBCLASS,
.bDeviceProtocol = DEVICE_PROTOCOL,
.bMaxPacketSize0 = USB_DEVICE_EP_CTRL_SIZE,
.idVendor = LE16(USB_DEVICE_VENDOR_ID),
.idProduct = LE16(USB_DEVICE_PRODUCT_ID),
.bcdDevice = LE16(USB_DEVICE_VERSION),
#ifdef USB_DEVICE_MANUFACTURE_NAME
.iManufacturer = 1,
.iManufacturer = 1,
#else
.iManufacturer = 0, // No manufacture string
.iManufacturer = 0, // No manufacture string
#endif
#ifdef USB_DEVICE_PRODUCT_NAME
.iProduct = 2,
.iProduct = 2,
#else
.iProduct = 0, // No product string
.iProduct = 0, // No product string
#endif
#if (defined USB_DEVICE_SERIAL_NAME || defined USB_DEVICE_GET_SERIAL_NAME_POINTER)
.iSerialNumber = 3,
.iSerialNumber = 3,
#else
.iSerialNumber = 0, // No serial string
.iSerialNumber = 0, // No serial string
#endif
.bNumConfigurations = 1
};
.bNumConfigurations = 1};
#if 0
#ifdef USB_DEVICE_HS_SUPPORT
# ifdef USB_DEVICE_HS_SUPPORT
//! USB Device Qualifier Descriptor for HS
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE usb_dev_qual_desc_t udc_device_qual = {
@ -108,77 +106,77 @@ UDC_DESC_STORAGE usb_dev_qual_desc_t udc_device_qual = {
.bMaxPacketSize0 = USB_DEVICE_EP_CTRL_SIZE,
.bNumConfigurations = 1
};
#endif
# endif
#endif
//! USB Device Configuration Descriptor filled for FS and HS
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udc_desc_t udc_desc = {
.conf.bLength = sizeof(usb_conf_desc_t),
.conf.bDescriptorType = USB_DT_CONFIGURATION,
.conf.wTotalLength = LE16(sizeof(udc_desc_t)),
.conf.bNumInterfaces = USB_DEVICE_NB_INTERFACE,
.conf.bConfigurationValue = 1,
.conf.iConfiguration = 0,
.conf.bmAttributes = /* USB_CONFIG_ATTR_MUST_SET | */ USB_DEVICE_ATTR,
.conf.bMaxPower = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
.conf.bLength = sizeof(usb_conf_desc_t),
.conf.bDescriptorType = USB_DT_CONFIGURATION,
.conf.wTotalLength = LE16(sizeof(udc_desc_t)),
.conf.bNumInterfaces = USB_DEVICE_NB_INTERFACE,
.conf.bConfigurationValue = 1,
.conf.iConfiguration = 0,
.conf.bmAttributes = /* USB_CONFIG_ATTR_MUST_SET | */ USB_DEVICE_ATTR,
.conf.bMaxPower = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
#ifdef KBD
.hid_kbd = UDI_HID_KBD_DESC,
.hid_kbd = UDI_HID_KBD_DESC,
#endif
#ifdef RAW
.hid_raw = UDI_HID_RAW_DESC,
.hid_raw = UDI_HID_RAW_DESC,
#endif
#ifdef MOU
.hid_mou = UDI_HID_MOU_DESC,
.hid_mou = UDI_HID_MOU_DESC,
#endif
#ifdef EXK
.hid_exk = UDI_HID_EXK_DESC,
.hid_exk = UDI_HID_EXK_DESC,
#endif
#ifdef CON
.hid_con = UDI_HID_CON_DESC,
.hid_con = UDI_HID_CON_DESC,
#endif
#ifdef NKRO
.hid_nkro = UDI_HID_NKRO_DESC,
.hid_nkro = UDI_HID_NKRO_DESC,
#endif
#ifdef CDC
.cdc_serial = CDC_DESCRIPTOR,
.cdc_serial = CDC_DESCRIPTOR,
#endif
};
UDC_DESC_STORAGE udi_api_t *udi_apis[USB_DEVICE_NB_INTERFACE] = {
#ifdef KBD
#ifdef KBD
&udi_api_hid_kbd,
#endif
#ifdef RAW
#endif
#ifdef RAW
&udi_api_hid_raw,
#endif
#ifdef MOU
#endif
#ifdef MOU
&udi_api_hid_mou,
#endif
#ifdef EXK
#endif
#ifdef EXK
&udi_api_hid_exk,
#endif
#ifdef CON
#endif
#ifdef CON
&udi_api_hid_con,
#endif
#ifdef NKRO
#endif
#ifdef NKRO
&udi_api_hid_nkro,
#endif
#ifdef CDC
&udi_api_cdc_comm, &udi_api_cdc_data,
#endif
#endif
#ifdef CDC
&udi_api_cdc_comm, &udi_api_cdc_data,
#endif
};
//! Add UDI with USB Descriptors FS & HS
UDC_DESC_STORAGE udc_config_speed_t udc_config_fshs[1] = {{
.desc = (usb_conf_desc_t UDC_DESC_STORAGE*)&udc_desc,
.udi_apis = udi_apis,
UDC_DESC_STORAGE udc_config_speed_t udc_config_fshs[1] = {{
.desc = (usb_conf_desc_t UDC_DESC_STORAGE *)&udc_desc,
.udi_apis = udi_apis,
}};
//! Add all information about USB Device in global structure for UDC
UDC_DESC_STORAGE udc_config_t udc_config = {
.confdev_lsfs = &udc_device_desc,
.conf_lsfs = udc_config_fshs,
.conf_lsfs = udc_config_fshs,
};
//@}

View file

@ -45,10 +45,10 @@
*/
#ifndef ARM_MATH_CM4
#define ARM_MATH_CM4
# define ARM_MATH_CM4
#endif
#undef LITTLE_ENDIAN //redefined in samd51j18a.h
#undef LITTLE_ENDIAN // redefined in samd51j18a.h
#include "samd51j18a.h"
#include "ui.h"
@ -68,37 +68,16 @@ static void ui_wakeup_handler(void)
}
#endif
void ui_init(void)
{
void ui_init(void) {}
}
void ui_powerdown(void) {}
void ui_powerdown(void)
{
void ui_wakeup_enable(void) {}
}
void ui_wakeup_disable(void) {}
void ui_wakeup_enable(void)
{
void ui_wakeup(void) {}
}
void ui_process(uint16_t framenumber) {}
void ui_wakeup_disable(void)
{
}
void ui_wakeup(void)
{
}
void ui_process(uint16_t framenumber)
{
}
void ui_kbd_led(uint8_t value)
{
}
void ui_kbd_led(uint8_t value) {}

View file

@ -73,4 +73,4 @@ void ui_process(uint16_t framenumber);
*/
void ui_kbd_led(uint8_t value);
#endif // _UI_H_
#endif // _UI_H_

View file

@ -48,11 +48,11 @@
#define SAMD11 DEVICE_MODE_ONLY
#ifndef ARM_MATH_CM4
#define ARM_MATH_CM4
# define ARM_MATH_CM4
#endif
#include "compiler.h"
#undef LITTLE_ENDIAN //redefined in samd51j18a.h
#undef LITTLE_ENDIAN // redefined in samd51j18a.h
#include "samd51j18a.h"
#include <stdbool.h>
#include <string.h>
@ -61,28 +61,28 @@
#include "usb.h"
/** Fields definition from a LPM TOKEN */
#define USB_LPM_ATTRIBUT_BLINKSTATE_MASK (0xF << 0)
#define USB_LPM_ATTRIBUT_HIRD_MASK (0xF << 4)
#define USB_LPM_ATTRIBUT_REMOTEWAKE_MASK (1 << 8)
#define USB_LPM_ATTRIBUT_BLINKSTATE(value) ((value & 0xF) << 0)
#define USB_LPM_ATTRIBUT_HIRD(value) ((value & 0xF) << 4)
#define USB_LPM_ATTRIBUT_REMOTEWAKE(value) ((value & 1) << 8)
#define USB_LPM_ATTRIBUT_BLINKSTATE_L1 USB_LPM_ATTRIBUT_BLINKSTATE(1)
#define USB_LPM_ATTRIBUT_BLINKSTATE_MASK (0xF << 0)
#define USB_LPM_ATTRIBUT_HIRD_MASK (0xF << 4)
#define USB_LPM_ATTRIBUT_REMOTEWAKE_MASK (1 << 8)
#define USB_LPM_ATTRIBUT_BLINKSTATE(value) ((value & 0xF) << 0)
#define USB_LPM_ATTRIBUT_HIRD(value) ((value & 0xF) << 4)
#define USB_LPM_ATTRIBUT_REMOTEWAKE(value) ((value & 1) << 8)
#define USB_LPM_ATTRIBUT_BLINKSTATE_L1 USB_LPM_ATTRIBUT_BLINKSTATE(1)
/**
* \brief Mask selecting the index part of an endpoint address
*/
#define USB_EP_ADDR_MASK 0x0f
#define USB_EP_ADDR_MASK 0x0f
/**
* \brief Endpoint transfer direction is IN
*/
#define USB_EP_DIR_IN 0x80
#define USB_EP_DIR_IN 0x80
/**
* \brief Endpoint transfer direction is OUT
*/
#define USB_EP_DIR_OUT 0x00
#define USB_EP_DIR_OUT 0x00
/**
* \name USB SRAM data containing pipe descriptor table
@ -120,24 +120,13 @@ static struct usb_endpoint_callback_parameter ep_callback_para;
* \internal USB Device IRQ Mask Bits Map
*/
static const uint16_t _usb_device_irq_bits[USB_DEVICE_CALLBACK_N] = {
USB_DEVICE_INTFLAG_SOF,
USB_DEVICE_INTFLAG_EORST,
USB_DEVICE_INTFLAG_WAKEUP | USB_DEVICE_INTFLAG_EORSM | USB_DEVICE_INTFLAG_UPRSM,
USB_DEVICE_INTFLAG_RAMACER,
USB_DEVICE_INTFLAG_SUSPEND,
USB_DEVICE_INTFLAG_LPMNYET,
USB_DEVICE_INTFLAG_LPMSUSP,
USB_DEVICE_INTFLAG_SOF, USB_DEVICE_INTFLAG_EORST, USB_DEVICE_INTFLAG_WAKEUP | USB_DEVICE_INTFLAG_EORSM | USB_DEVICE_INTFLAG_UPRSM, USB_DEVICE_INTFLAG_RAMACER, USB_DEVICE_INTFLAG_SUSPEND, USB_DEVICE_INTFLAG_LPMNYET, USB_DEVICE_INTFLAG_LPMSUSP,
};
/**
* \internal USB Device IRQ Mask Bits Map
*/
static const uint8_t _usb_endpoint_irq_bits[USB_DEVICE_EP_CALLBACK_N] = {
USB_DEVICE_EPINTFLAG_TRCPT_Msk,
USB_DEVICE_EPINTFLAG_TRFAIL_Msk,
USB_DEVICE_EPINTFLAG_RXSTP,
USB_DEVICE_EPINTFLAG_STALL_Msk
};
static const uint8_t _usb_endpoint_irq_bits[USB_DEVICE_EP_CALLBACK_N] = {USB_DEVICE_EPINTFLAG_TRCPT_Msk, USB_DEVICE_EPINTFLAG_TRFAIL_Msk, USB_DEVICE_EPINTFLAG_RXSTP, USB_DEVICE_EPINTFLAG_STALL_Msk};
/**
* \brief Registers a USB device callback
@ -155,10 +144,7 @@ static const uint8_t _usb_endpoint_irq_bits[USB_DEVICE_EP_CALLBACK_N] = {
* \return Status of the registration operation.
* \retval STATUS_OK The callback was registered successfully.
*/
enum status_code usb_device_register_callback(struct usb_module *module_inst,
enum usb_device_callback callback_type,
usb_device_callback_t callback_func)
{
enum status_code usb_device_register_callback(struct usb_module *module_inst, enum usb_device_callback callback_type, usb_device_callback_t callback_func) {
/* Sanity check arguments */
Assert(module_inst);
Assert(callback_func);
@ -184,9 +170,7 @@ enum status_code usb_device_register_callback(struct usb_module *module_inst,
* \return Status of the de-registration operation.
* \retval STATUS_OK The callback was unregistered successfully.
*/
enum status_code usb_device_unregister_callback(struct usb_module *module_inst,
enum usb_device_callback callback_type)
{
enum status_code usb_device_unregister_callback(struct usb_module *module_inst, enum usb_device_callback callback_type) {
/* Sanity check arguments */
Assert(module_inst);
@ -211,9 +195,7 @@ enum status_code usb_device_unregister_callback(struct usb_module *module_inst,
* \return Status of the callback enable operation.
* \retval STATUS_OK The callback was enabled successfully.
*/
enum status_code usb_device_enable_callback(struct usb_module *module_inst,
enum usb_device_callback callback_type)
{
enum status_code usb_device_enable_callback(struct usb_module *module_inst, enum usb_device_callback callback_type) {
/* Sanity check arguments */
Assert(module_inst);
Assert(module_inst->hw);
@ -240,9 +222,7 @@ enum status_code usb_device_enable_callback(struct usb_module *module_inst,
* \return Status of the callback disable operation.
* \retval STATUS_OK The callback was disabled successfully.
*/
enum status_code usb_device_disable_callback(struct usb_module *module_inst,
enum usb_device_callback callback_type)
{
enum status_code usb_device_disable_callback(struct usb_module *module_inst, enum usb_device_callback callback_type) {
/* Sanity check arguments */
Assert(module_inst);
Assert(module_inst->hw);
@ -272,11 +252,7 @@ enum status_code usb_device_disable_callback(struct usb_module *module_inst,
* \return Status of the registration operation.
* \retval STATUS_OK The callback was registered successfully.
*/
enum status_code usb_device_endpoint_register_callback(
struct usb_module *module_inst, uint8_t ep_num,
enum usb_device_endpoint_callback callback_type,
usb_device_endpoint_callback_t callback_func)
{
enum status_code usb_device_endpoint_register_callback(struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type, usb_device_endpoint_callback_t callback_func) {
/* Sanity check arguments */
Assert(module_inst);
Assert(ep_num < USB_EPT_NUM);
@ -304,10 +280,7 @@ enum status_code usb_device_endpoint_register_callback(
* \return Status of the de-registration operation.
* \retval STATUS_OK The callback was unregistered successfully.
*/
enum status_code usb_device_endpoint_unregister_callback(
struct usb_module *module_inst, uint8_t ep_num,
enum usb_device_endpoint_callback callback_type)
{
enum status_code usb_device_endpoint_unregister_callback(struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type) {
/* Sanity check arguments */
Assert(module_inst);
Assert(ep_num < USB_EPT_NUM);
@ -334,10 +307,7 @@ enum status_code usb_device_endpoint_unregister_callback(
* \return Status of the callback enable operation.
* \retval STATUS_OK The callback was enabled successfully.
*/
enum status_code usb_device_endpoint_enable_callback(
struct usb_module *module_inst, uint8_t ep,
enum usb_device_endpoint_callback callback_type)
{
enum status_code usb_device_endpoint_enable_callback(struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type) {
/* Sanity check arguments */
Assert(module_inst);
Assert(module_inst->hw);
@ -349,7 +319,7 @@ enum status_code usb_device_endpoint_enable_callback(
module_inst->device_endpoint_enabled_callback_mask[ep_num] |= _usb_endpoint_irq_bits[callback_type];
if (callback_type == USB_DEVICE_ENDPOINT_CALLBACK_TRCPT) {
if (ep_num == 0) { // control endpoint
if (ep_num == 0) { // control endpoint
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT0 | USB_DEVICE_EPINTENSET_TRCPT1;
} else if (ep & USB_EP_DIR_IN) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT1;
@ -359,7 +329,7 @@ enum status_code usb_device_endpoint_enable_callback(
}
if (callback_type == USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL) {
if (ep_num == 0) { // control endpoint
if (ep_num == 0) { // control endpoint
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRFAIL0 | USB_DEVICE_EPINTENSET_TRFAIL1;
} else if (ep & USB_EP_DIR_IN) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRFAIL1;
@ -395,10 +365,7 @@ enum status_code usb_device_endpoint_enable_callback(
* \return Status of the callback disable operation.
* \retval STATUS_OK The callback was disabled successfully.
*/
enum status_code usb_device_endpoint_disable_callback(
struct usb_module *module_inst, uint8_t ep,
enum usb_device_endpoint_callback callback_type)
{
enum status_code usb_device_endpoint_disable_callback(struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type) {
/* Sanity check arguments */
Assert(module_inst);
Assert(module_inst->hw);
@ -410,17 +377,17 @@ enum status_code usb_device_endpoint_disable_callback(
module_inst->device_endpoint_enabled_callback_mask[ep_num] &= ~_usb_endpoint_irq_bits[callback_type];
if (callback_type == USB_DEVICE_ENDPOINT_CALLBACK_TRCPT) {
if (ep_num == 0) { // control endpoint
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT0 | USB_DEVICE_EPINTENCLR_TRCPT1;
if (ep_num == 0) { // control endpoint
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT0 | USB_DEVICE_EPINTENCLR_TRCPT1;
} else if (ep & USB_EP_DIR_IN) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT1;
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT1;
} else {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT0;
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT0;
}
}
if (callback_type == USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL) {
if (ep_num == 0) { // control endpoint
if (ep_num == 0) { // control endpoint
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRFAIL0 | USB_DEVICE_EPINTENCLR_TRFAIL1;
} else if (ep & USB_EP_DIR_IN) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRFAIL1;
@ -460,16 +427,15 @@ enum status_code usb_device_endpoint_disable_callback(
*
* \param[out] ep_config Configuration structure to initialize to default values
*/
void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *ep_config)
{
void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *ep_config) {
/* Sanity check arguments */
Assert(ep_config);
/* Write default config to config struct */
ep_config->ep_address = 0;
ep_config->ep_size = USB_ENDPOINT_8_BYTE;
ep_config->auto_zlp = false;
ep_config->ep_type = USB_DEVICE_ENDPOINT_TYPE_CONTROL;
ep_config->ep_size = USB_ENDPOINT_8_BYTE;
ep_config->auto_zlp = false;
ep_config->ep_type = USB_DEVICE_ENDPOINT_TYPE_CONTROL;
}
/**
@ -486,25 +452,22 @@ void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *
* \retval STATUS_OK The device endpoint was configured successfully
* \retval STATUS_ERR_DENIED The endpoint address is already configured
*/
enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
struct usb_device_endpoint_config *ep_config)
{
enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst, struct usb_device_endpoint_config *ep_config) {
/* Sanity check arguments */
Assert(module_inst);
Assert(ep_config);
uint8_t ep_num = ep_config->ep_address & USB_EP_ADDR_MASK;
uint8_t ep_num = ep_config->ep_address & USB_EP_ADDR_MASK;
uint8_t ep_bank = (ep_config->ep_address & USB_EP_DIR_IN) ? 1 : 0;
switch (ep_config->ep_type) {
case USB_DEVICE_ENDPOINT_TYPE_DISABLE:
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(0) | USB_DEVICE_EPCFG_EPTYPE1(0);
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(0) | USB_DEVICE_EPCFG_EPTYPE1(0);
return STATUS_OK;
case USB_DEVICE_ENDPOINT_TYPE_CONTROL:
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0 && \
(module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(1) | USB_DEVICE_EPCFG_EPTYPE1(1);
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0 && (module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(1) | USB_DEVICE_EPCFG_EPTYPE1(1);
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK0RDY;
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
} else {
@ -523,14 +486,14 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
case USB_DEVICE_ENDPOINT_TYPE_ISOCHRONOUS:
if (ep_bank) {
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0){
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE1(2);
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
} else {
return STATUS_ERR_DENIED;
}
} else {
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0){
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE0(2);
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK0RDY;
} else {
@ -541,14 +504,14 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
case USB_DEVICE_ENDPOINT_TYPE_BULK:
if (ep_bank) {
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0){
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE1(3);
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
} else {
return STATUS_ERR_DENIED;
}
} else {
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0){
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE0(3);
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK0RDY;
} else {
@ -559,14 +522,14 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
case USB_DEVICE_ENDPOINT_TYPE_INTERRUPT:
if (ep_bank) {
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0){
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE1_Msk) == 0) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE1(4);
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
} else {
return STATUS_ERR_DENIED;
}
} else {
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0){
if ((module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg & USB_DEVICE_EPCFG_EPTYPE0_Msk) == 0) {
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPCFG.reg |= USB_DEVICE_EPCFG_EPTYPE0(4);
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK0RDY;
} else {
@ -583,7 +546,7 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
if (true == ep_config->auto_zlp) {
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[ep_bank].PCKSIZE.reg |= USB_DEVICE_PCKSIZE_AUTO_ZLP;
} else {
} else {
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[ep_bank].PCKSIZE.reg &= ~USB_DEVICE_PCKSIZE_AUTO_ZLP;
}
@ -598,8 +561,7 @@ enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
*
* \return \c true if endpoint is configured and ready to use
*/
bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t ep)
{
bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t ep) {
uint8_t ep_num = ep & USB_EP_ADDR_MASK;
uint8_t flag;
@ -611,15 +573,13 @@ bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t e
return ((enum usb_device_endpoint_type)(flag) != USB_DEVICE_ENDPOINT_TYPE_DISABLE);
}
/**
* \brief Abort ongoing job on the endpoint
*
* \param module_inst Pointer to USB software instance struct
* \param ep Endpoint address
*/
void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep)
{
void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep) {
uint8_t ep_num;
ep_num = ep & USB_EP_ADDR_MASK;
@ -643,8 +603,7 @@ void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep)
*
* \return \c true if the endpoint is halted
*/
bool usb_device_endpoint_is_halted(struct usb_module *module_inst, uint8_t ep)
{
bool usb_device_endpoint_is_halted(struct usb_module *module_inst, uint8_t ep) {
uint8_t ep_num = ep & USB_EP_ADDR_MASK;
if (ep & USB_EP_DIR_IN) {
@ -660,8 +619,7 @@ bool usb_device_endpoint_is_halted(struct usb_module *module_inst, uint8_t ep)
* \param module_inst Pointer to USB software instance struct
* \param ep Endpoint address
*/
void usb_device_endpoint_set_halt(struct usb_module *module_inst, uint8_t ep)
{
void usb_device_endpoint_set_halt(struct usb_module *module_inst, uint8_t ep) {
uint8_t ep_num = ep & USB_EP_ADDR_MASK;
// Stall endpoint
@ -678,8 +636,7 @@ void usb_device_endpoint_set_halt(struct usb_module *module_inst, uint8_t ep)
* \param module_inst Pointer to USB software instance struct
* \param ep Endpoint address
*/
void usb_device_endpoint_clear_halt(struct usb_module *module_inst, uint8_t ep)
{
void usb_device_endpoint_clear_halt(struct usb_module *module_inst, uint8_t ep) {
uint8_t ep_num = ep & USB_EP_ADDR_MASK;
if (ep & USB_EP_DIR_IN) {
@ -717,9 +674,7 @@ void usb_device_endpoint_clear_halt(struct usb_module *module_inst, uint8_t ep)
* \retval STATUS_OK Job started successfully
* \retval STATUS_ERR_DENIED Endpoint is not ready
*/
enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_inst,uint8_t ep_num,
uint8_t* pbuf, uint32_t buf_size)
{
enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size) {
/* Sanity check arguments */
Assert(module_inst);
Assert(module_inst->hw);
@ -732,10 +687,10 @@ enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_
};
/* get endpoint configuration from setting register */
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].ADDR.reg = (uint32_t)pbuf;
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].ADDR.reg = (uint32_t)pbuf;
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].PCKSIZE.bit.MULTI_PACKET_SIZE = 0;
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT = buf_size;
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK1RDY;
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT = buf_size;
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_BK1RDY;
return STATUS_OK;
}
@ -752,9 +707,7 @@ enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_
* \retval STATUS_OK Job started successfully
* \retval STATUS_ERR_DENIED Endpoint is not ready
*/
enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_inst,uint8_t ep_num,
uint8_t* pbuf, uint32_t buf_size)
{
enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size) {
/* Sanity check arguments */
Assert(module_inst);
Assert(module_inst->hw);
@ -767,10 +720,10 @@ enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_i
};
/* get endpoint configuration from setting register */
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].ADDR.reg = (uint32_t)pbuf;
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].ADDR.reg = (uint32_t)pbuf;
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE = buf_size;
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT = 0;
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK0RDY;
usb_descriptor_table.usb_endpoint_table[ep_num].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT = 0;
module_inst->hw->DEVICE.DeviceEndpoint[ep_num].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK0RDY;
return STATUS_OK;
}
@ -785,24 +738,21 @@ enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_i
* \retval STATUS_OK Job started successfully
* \retval STATUS_ERR_DENIED Endpoint is not ready
*/
enum status_code usb_device_endpoint_setup_buffer_job(struct usb_module *module_inst,
uint8_t* pbuf)
{
enum status_code usb_device_endpoint_setup_buffer_job(struct usb_module *module_inst, uint8_t *pbuf) {
/* Sanity check arguments */
Assert(module_inst);
Assert(module_inst->hw);
/* get endpoint configuration from setting register */
usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].ADDR.reg = (uint32_t)pbuf;
usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].ADDR.reg = (uint32_t)pbuf;
usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE = 8;
usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT = 0;
module_inst->hw->DEVICE.DeviceEndpoint[0].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK0RDY;
usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT = 0;
module_inst->hw->DEVICE.DeviceEndpoint[0].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK0RDY;
return STATUS_OK;
}
static void _usb_device_interrupt_handler(void)
{
static void _usb_device_interrupt_handler(void) {
uint16_t ep_inst;
uint16_t flags, flags_run;
ep_inst = _usb_instances->hw->DEVICE.EPINTSMRY.reg;
@ -812,21 +762,16 @@ static void _usb_device_interrupt_handler(void)
int i;
/* get interrupt flags */
flags = _usb_instances->hw->DEVICE.INTFLAG.reg;
flags_run = flags &
_usb_instances->device_enabled_callback_mask &
_usb_instances->device_registered_callback_mask;
flags = _usb_instances->hw->DEVICE.INTFLAG.reg;
flags_run = flags & _usb_instances->device_enabled_callback_mask & _usb_instances->device_registered_callback_mask;
for (i = 0; i < USB_DEVICE_CALLBACK_N; i ++) {
for (i = 0; i < USB_DEVICE_CALLBACK_N; i++) {
if (flags & _usb_device_irq_bits[i]) {
_usb_instances->hw->DEVICE.INTFLAG.reg =
_usb_device_irq_bits[i];
_usb_instances->hw->DEVICE.INTFLAG.reg = _usb_device_irq_bits[i];
}
if (flags_run & _usb_device_irq_bits[i]) {
if (i == USB_DEVICE_CALLBACK_LPMSUSP) {
device_callback_lpm_wakeup_enable =
usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].EXTREG.bit.VARIABLE
& USB_LPM_ATTRIBUT_REMOTEWAKE_MASK;
device_callback_lpm_wakeup_enable = usb_descriptor_table.usb_endpoint_table[0].DeviceDescBank[0].EXTREG.bit.VARIABLE & USB_LPM_ATTRIBUT_REMOTEWAKE_MASK;
}
(_usb_instances->device_callback[i])(_usb_instances, &device_callback_lpm_wakeup_enable);
}
@ -836,25 +781,22 @@ static void _usb_device_interrupt_handler(void)
/* endpoint interrupt */
for (uint8_t i = 0; i < USB_EPT_NUM; i++) {
if (ep_inst & (1 << i)) {
flags = _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg;
flags_run = flags &
_usb_instances->device_endpoint_enabled_callback_mask[i] &
_usb_instances->device_endpoint_registered_callback_mask[i];
flags = _usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg;
flags_run = flags & _usb_instances->device_endpoint_enabled_callback_mask[i] & _usb_instances->device_endpoint_registered_callback_mask[i];
// endpoint transfer stall interrupt
if (flags & USB_DEVICE_EPINTFLAG_STALL_Msk) {
if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_STALL1) {
_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL1;
ep_callback_para.endpoint_address = USB_EP_DIR_IN | i;
ep_callback_para.endpoint_address = USB_EP_DIR_IN | i;
} else if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_STALL0) {
_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL0;
ep_callback_para.endpoint_address = USB_EP_DIR_OUT | i;
ep_callback_para.endpoint_address = USB_EP_DIR_OUT | i;
}
if (flags_run & USB_DEVICE_EPINTFLAG_STALL_Msk) {
(_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_STALL])(_usb_instances,&ep_callback_para);
(_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_STALL])(_usb_instances, &ep_callback_para);
}
return;
}
@ -862,9 +804,9 @@ static void _usb_device_interrupt_handler(void)
// endpoint received setup interrupt
if (flags & USB_DEVICE_EPINTFLAG_RXSTP) {
_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
if(_usb_instances->device_endpoint_enabled_callback_mask[i] & _usb_endpoint_irq_bits[USB_DEVICE_ENDPOINT_CALLBACK_RXSTP]) {
if (_usb_instances->device_endpoint_enabled_callback_mask[i] & _usb_endpoint_irq_bits[USB_DEVICE_ENDPOINT_CALLBACK_RXSTP]) {
ep_callback_para.received_bytes = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT);
(_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_RXSTP])(_usb_instances,&ep_callback_para);
(_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_RXSTP])(_usb_instances, &ep_callback_para);
}
return;
}
@ -873,17 +815,17 @@ static void _usb_device_interrupt_handler(void)
if (flags & USB_DEVICE_EPINTFLAG_TRCPT_Msk) {
if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1) {
_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
ep_callback_para.endpoint_address = USB_EP_DIR_IN | i;
ep_callback_para.sent_bytes = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT);
ep_callback_para.endpoint_address = USB_EP_DIR_IN | i;
ep_callback_para.sent_bytes = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT);
} else if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT0) {
_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
ep_callback_para.endpoint_address = USB_EP_DIR_OUT | i;
ep_callback_para.received_bytes = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT);
ep_callback_para.out_buffer_size = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE);
ep_callback_para.endpoint_address = USB_EP_DIR_OUT | i;
ep_callback_para.received_bytes = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT);
ep_callback_para.out_buffer_size = (uint16_t)(usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE);
}
if(flags_run & USB_DEVICE_EPINTFLAG_TRCPT_Msk) {
(_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_TRCPT])(_usb_instances,&ep_callback_para);
if (flags_run & USB_DEVICE_EPINTFLAG_TRCPT_Msk) {
(_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_TRCPT])(_usb_instances, &ep_callback_para);
}
return;
}
@ -899,7 +841,7 @@ static void _usb_device_interrupt_handler(void)
if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1) {
return;
}
} else if(_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRFAIL0) {
} else if (_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRFAIL0) {
_usb_instances->hw->DEVICE.DeviceEndpoint[i].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRFAIL0;
if (usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].STATUS_BK.reg & USB_DEVICE_STATUS_BK_ERRORFLOW) {
usb_descriptor_table.usb_endpoint_table[i].DeviceDescBank[0].STATUS_BK.reg &= ~USB_DEVICE_STATUS_BK_ERRORFLOW;
@ -910,8 +852,8 @@ static void _usb_device_interrupt_handler(void)
}
}
if(flags_run & USB_DEVICE_EPINTFLAG_TRFAIL_Msk) {
(_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL])(_usb_instances,&ep_callback_para);
if (flags_run & USB_DEVICE_EPINTFLAG_TRFAIL_Msk) {
(_usb_instances->device_endpoint_callback[i][USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL])(_usb_instances, &ep_callback_para);
}
return;
}
@ -925,13 +867,13 @@ static void _usb_device_interrupt_handler(void)
*
* \param module_inst pointer to USB module instance
*/
void usb_enable(struct usb_module *module_inst)
{
void usb_enable(struct usb_module *module_inst) {
Assert(module_inst);
Assert(module_inst->hw);
module_inst->hw->DEVICE.CTRLA.reg |= USB_CTRLA_ENABLE;
while (module_inst->hw->DEVICE.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE);
while (module_inst->hw->DEVICE.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE)
;
}
/**
@ -939,68 +881,56 @@ void usb_enable(struct usb_module *module_inst)
*
* \param module_inst pointer to USB module instance
*/
void usb_disable(struct usb_module *module_inst)
{
void usb_disable(struct usb_module *module_inst) {
Assert(module_inst);
Assert(module_inst->hw);
module_inst->hw->DEVICE.INTENCLR.reg = USB_DEVICE_INTENCLR_MASK;
module_inst->hw->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_MASK;
module_inst->hw->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_MASK;
module_inst->hw->DEVICE.CTRLA.reg &= ~USB_CTRLA_ENABLE;
while (module_inst->hw->DEVICE.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE);
while (module_inst->hw->DEVICE.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE)
;
}
/**
* \brief Interrupt handler for the USB module.
*/
void USB_0_Handler(void)
{
void USB_0_Handler(void) {
if (_usb_instances->hw->DEVICE.CTRLA.bit.MODE) {
} else {
/*device mode ISR */
_usb_device_interrupt_handler();
}
}
void USB_1_Handler(void)
{
_usb_device_interrupt_handler();
}
void USB_1_Handler(void) { _usb_device_interrupt_handler(); }
void USB_2_Handler(void)
{
_usb_device_interrupt_handler();
}
void USB_2_Handler(void) { _usb_device_interrupt_handler(); }
void USB_3_Handler(void)
{
_usb_device_interrupt_handler();
}
void USB_3_Handler(void) { _usb_device_interrupt_handler(); }
/**
* \brief Get the default USB module settings
*
* \param[out] module_config Configuration structure to initialize to default values
*/
void usb_get_config_defaults(struct usb_config *module_config)
{
void usb_get_config_defaults(struct usb_config *module_config) {
Assert(module_config);
/* Sanity check arguments */
Assert(module_config);
/* Write default configuration to config struct */
module_config->select_host_mode = 0;
module_config->run_in_standby = 1;
module_config->run_in_standby = 1;
module_config->source_generator = 0;
module_config->speed_mode = USB_SPEED_FULL;
module_config->speed_mode = USB_SPEED_FULL;
}
#define NVM_USB_PAD_TRANSN_POS 45
#define NVM_USB_PAD_TRANSN_POS 45
#define NVM_USB_PAD_TRANSN_SIZE 5
#define NVM_USB_PAD_TRANSP_POS 50
#define NVM_USB_PAD_TRANSP_POS 50
#define NVM_USB_PAD_TRANSP_SIZE 5
#define NVM_USB_PAD_TRIM_POS 55
#define NVM_USB_PAD_TRIM_POS 55
#define NVM_USB_PAD_TRIM_SIZE 3
/**
@ -1020,56 +950,61 @@ void usb_get_config_defaults(struct usb_config *module_config)
#define GCLK_USB 10
enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
struct usb_config *module_config)
{
enum status_code usb_init(struct usb_module *module_inst, Usb *const hw, struct usb_config *module_config) {
/* Sanity check arguments */
Assert(hw);
Assert(module_inst);
Assert(module_config);
uint32_t i,j;
uint32_t i, j;
uint32_t pad_transn, pad_transp, pad_trim;
Gclk *pgclk = GCLK;
Mclk *pmclk = MCLK;
Port *pport = PORT;
Oscctrl *posc = OSCCTRL;
Gclk * pgclk = GCLK;
Mclk * pmclk = MCLK;
Port * pport = PORT;
Oscctrl *posc = OSCCTRL;
_usb_instances = module_inst;
/* Associate the software module instance with the hardware module */
module_inst->hw = hw;
//setup peripheral and synchronous bus clocks to USB
pmclk->AHBMASK.bit.USB_ = 1;
// setup peripheral and synchronous bus clocks to USB
pmclk->AHBMASK.bit.USB_ = 1;
pmclk->APBBMASK.bit.USB_ = 1;
/* Set up the USB DP/DN pins */
pport->Group[0].PMUX[12].reg = 0x77; //PA24, PA25, function column H for USB D-, D+
pport->Group[0].PMUX[12].reg = 0x77; // PA24, PA25, function column H for USB D-, D+
pport->Group[0].PINCFG[24].bit.PMUXEN = 1;
pport->Group[0].PINCFG[25].bit.PMUXEN = 1;
pport->Group[1].PMUX[11].bit.PMUXE = 7; //PB22, function column H for USB SOF_1KHz output
pport->Group[1].PMUX[11].bit.PMUXE = 7; // PB22, function column H for USB SOF_1KHz output
pport->Group[1].PINCFG[22].bit.PMUXEN = 1;
//configure and enable DFLL for USB clock recovery mode at 48MHz
// configure and enable DFLL for USB clock recovery mode at 48MHz
posc->DFLLCTRLA.bit.ENABLE = 0;
while (posc->DFLLSYNC.bit.ENABLE);
while (posc->DFLLSYNC.bit.DFLLCTRLB);
while (posc->DFLLSYNC.bit.ENABLE)
;
while (posc->DFLLSYNC.bit.DFLLCTRLB)
;
posc->DFLLCTRLB.bit.USBCRM = 1;
while (posc->DFLLSYNC.bit.DFLLCTRLB);
while (posc->DFLLSYNC.bit.DFLLCTRLB)
;
posc->DFLLCTRLB.bit.MODE = 1;
while (posc->DFLLSYNC.bit.DFLLCTRLB);
while (posc->DFLLSYNC.bit.DFLLCTRLB)
;
posc->DFLLCTRLB.bit.QLDIS = 0;
while (posc->DFLLSYNC.bit.DFLLCTRLB);
while (posc->DFLLSYNC.bit.DFLLCTRLB)
;
posc->DFLLCTRLB.bit.CCDIS = 1;
posc->DFLLMUL.bit.MUL = 0xbb80; //4800 x 1KHz
while (posc->DFLLSYNC.bit.DFLLMUL);
posc->DFLLMUL.bit.MUL = 0xbb80; // 4800 x 1KHz
while (posc->DFLLSYNC.bit.DFLLMUL)
;
posc->DFLLCTRLA.bit.ENABLE = 1;
while (posc->DFLLSYNC.bit.ENABLE);
while (posc->DFLLSYNC.bit.ENABLE)
;
/* Setup clock for module */
pgclk->PCHCTRL[GCLK_USB].bit.GEN = 0;
pgclk->PCHCTRL[GCLK_USB].bit.GEN = 0;
pgclk->PCHCTRL[GCLK_USB].bit.CHEN = 1;
/* Reset */
@ -1084,21 +1019,21 @@ enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
/* Load Pad Calibration */
pad_transn = (USB_FUSES_TRANSN_ADDR >> USB_FUSES_TRANSN_Pos) & USB_FUSES_TRANSN_Msk;
pad_transn = (USB_FUSES_TRANSN_ADDR >> USB_FUSES_TRANSN_Pos) & USB_FUSES_TRANSN_Msk;
if (pad_transn == 0x1F) {
pad_transn = 5;
}
hw->DEVICE.PADCAL.bit.TRANSN = pad_transn;
pad_transp = (USB_FUSES_TRANSP_ADDR >> USB_FUSES_TRANSP_Pos) & USB_FUSES_TRANSP_Msk;
pad_transp = (USB_FUSES_TRANSP_ADDR >> USB_FUSES_TRANSP_Pos) & USB_FUSES_TRANSP_Msk;
if (pad_transp == 0x1F) {
pad_transp = 29;
}
hw->DEVICE.PADCAL.bit.TRANSP = pad_transp;
pad_trim = (USB_FUSES_TRIM_ADDR >> USB_FUSES_TRIM_Pos) & USB_FUSES_TRIM_Msk;
pad_trim = (USB_FUSES_TRIM_ADDR >> USB_FUSES_TRIM_Pos) & USB_FUSES_TRIM_Msk;
if (pad_trim == 0x07) {
pad_trim = 3;
}
@ -1106,32 +1041,31 @@ enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
hw->DEVICE.PADCAL.bit.TRIM = pad_trim;
/* Set the configuration */
hw->DEVICE.CTRLA.bit.MODE = module_config->select_host_mode;
hw->DEVICE.CTRLA.bit.MODE = module_config->select_host_mode;
hw->DEVICE.CTRLA.bit.RUNSTDBY = module_config->run_in_standby;
hw->DEVICE.DESCADD.reg = (uint32_t)(&usb_descriptor_table.usb_endpoint_table[0]);
hw->DEVICE.DESCADD.reg = (uint32_t)(&usb_descriptor_table.usb_endpoint_table[0]);
if (USB_SPEED_FULL == module_config->speed_mode) {
module_inst->hw->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_FS_Val;
} else if(USB_SPEED_LOW == module_config->speed_mode) {
} else if (USB_SPEED_LOW == module_config->speed_mode) {
module_inst->hw->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_LS_Val;
}
memset((uint8_t *)(&usb_descriptor_table.usb_endpoint_table[0]), 0,
sizeof(usb_descriptor_table.usb_endpoint_table));
memset((uint8_t *)(&usb_descriptor_table.usb_endpoint_table[0]), 0, sizeof(usb_descriptor_table.usb_endpoint_table));
/* device callback related */
for (i = 0; i < USB_DEVICE_CALLBACK_N; i++) {
module_inst->device_callback[i] = NULL;
}
for (i = 0; i < USB_EPT_NUM; i++) {
for(j = 0; j < USB_DEVICE_EP_CALLBACK_N; j++) {
for (j = 0; j < USB_DEVICE_EP_CALLBACK_N; j++) {
module_inst->device_endpoint_callback[i][j] = NULL;
}
}
module_inst->device_registered_callback_mask = 0;
module_inst->device_enabled_callback_mask = 0;
module_inst->device_enabled_callback_mask = 0;
for (j = 0; j < USB_EPT_NUM; j++) {
module_inst->device_endpoint_registered_callback_mask[j] = 0;
module_inst->device_endpoint_enabled_callback_mask[j] = 0;
module_inst->device_endpoint_enabled_callback_mask[j] = 0;
}
/* Enable interrupts for this USB module */
@ -1141,4 +1075,3 @@ enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
return STATUS_OK;
}

View file

@ -233,8 +233,8 @@ typedef void (*usb_host_pipe_callback_t)(struct usb_module *module_inst, void *)
* \name Device Callback Functions Types
* @{
*/
typedef void (*usb_device_callback_t)(struct usb_module *module_inst, void* pointer);
typedef void (*usb_device_endpoint_callback_t)(struct usb_module *module_inst, void* pointer);
typedef void (*usb_device_callback_t)(struct usb_module *module_inst, void *pointer);
typedef void (*usb_device_endpoint_callback_t)(struct usb_module *module_inst, void *pointer);
/** @} */
/** USB configurations */
@ -247,7 +247,7 @@ struct usb_config {
// enum gclk_generator source_generator;
uint8_t source_generator;
/** Speed mode */
//enum usb_speed speed_mode;
// enum usb_speed speed_mode;
uint8_t speed_mode;
};
@ -263,7 +263,7 @@ struct usb_module {
Usb *hw;
/** Array to store device related callback functions */
usb_device_callback_t device_callback[USB_DEVICE_CALLBACK_N];
usb_device_callback_t device_callback[USB_DEVICE_CALLBACK_N];
usb_device_endpoint_callback_t device_endpoint_callback[USB_EPT_NUM][USB_DEVICE_EP_CALLBACK_N];
/** Bit mask for device callbacks registered */
uint16_t device_registered_callback_mask;
@ -292,7 +292,7 @@ struct usb_endpoint_callback_parameter {
uint16_t received_bytes;
uint16_t sent_bytes;
uint16_t out_buffer_size;
uint8_t endpoint_address;
uint8_t endpoint_address;
};
void usb_enable(struct usb_module *module_inst);
@ -303,8 +303,7 @@ void usb_disable(struct usb_module *module_inst);
*
* \param module_inst Pointer to USB module instance
*/
static inline uint8_t usb_get_state_machine_status(struct usb_module *module_inst)
{
static inline uint8_t usb_get_state_machine_status(struct usb_module *module_inst) {
/* Sanity check arguments */
Assert(module_inst);
Assert(module_inst->hw);
@ -312,29 +311,22 @@ static inline uint8_t usb_get_state_machine_status(struct usb_module *module_ins
return module_inst->hw->DEVICE.FSMSTATUS.reg;
}
void usb_get_config_defaults(struct usb_config *module_config);
enum status_code usb_init(struct usb_module *module_inst, Usb *const hw,
struct usb_config *module_config);
void usb_get_config_defaults(struct usb_config *module_config);
enum status_code usb_init(struct usb_module *module_inst, Usb *const hw, struct usb_config *module_config);
/**
* \brief Attach USB device to the bus
*
* \param module_inst Pointer to USB device module instance
*/
static inline void usb_device_attach(struct usb_module *module_inst)
{
module_inst->hw->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_DETACH;
}
static inline void usb_device_attach(struct usb_module *module_inst) { module_inst->hw->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_DETACH; }
/**
* \brief Detach USB device from the bus
*
* \param module_inst Pointer to USB device module instance
*/
static inline void usb_device_detach(struct usb_module *module_inst)
{
module_inst->hw->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_DETACH;
}
static inline void usb_device_detach(struct usb_module *module_inst) { module_inst->hw->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_DETACH; }
/**
* \brief Get the speed mode of USB device
@ -342,8 +334,7 @@ static inline void usb_device_detach(struct usb_module *module_inst)
* \param module_inst Pointer to USB device module instance
* \return USB Speed mode (\ref usb_speed).
*/
static inline enum usb_speed usb_device_get_speed(struct usb_module *module_inst)
{
static inline enum usb_speed usb_device_get_speed(struct usb_module *module_inst) {
if (!(module_inst->hw->DEVICE.STATUS.reg & USB_DEVICE_STATUS_SPEED_Msk)) {
return USB_SPEED_FULL;
} else {
@ -357,10 +348,7 @@ static inline enum usb_speed usb_device_get_speed(struct usb_module *module_inst
* \param module_inst Pointer to USB device module instance
* \return USB device address value.
*/
static inline uint8_t usb_device_get_address(struct usb_module *module_inst)
{
return ((uint8_t)(module_inst->hw->DEVICE.DADD.bit.DADD));
}
static inline uint8_t usb_device_get_address(struct usb_module *module_inst) { return ((uint8_t)(module_inst->hw->DEVICE.DADD.bit.DADD)); }
/**
* \brief Set the speed mode of USB device
@ -368,10 +356,7 @@ static inline uint8_t usb_device_get_address(struct usb_module *module_inst)
* \param module_inst Pointer to USB device module instance
* \param address USB device address value
*/
static inline void usb_device_set_address(struct usb_module *module_inst, uint8_t address)
{
module_inst->hw->DEVICE.DADD.reg = USB_DEVICE_DADD_ADDEN | address;
}
static inline void usb_device_set_address(struct usb_module *module_inst, uint8_t address) { module_inst->hw->DEVICE.DADD.reg = USB_DEVICE_DADD_ADDEN | address; }
/**
* \brief Get the frame number of USB device
@ -379,10 +364,7 @@ static inline void usb_device_set_address(struct usb_module *module_inst, uint8_
* \param module_inst Pointer to USB device module instance
* \return USB device frame number value.
*/
static inline uint16_t usb_device_get_frame_number(struct usb_module *module_inst)
{
return ((uint16_t)(module_inst->hw->DEVICE.FNUM.bit.FNUM));
}
static inline uint16_t usb_device_get_frame_number(struct usb_module *module_inst) { return ((uint16_t)(module_inst->hw->DEVICE.FNUM.bit.FNUM)); }
/**
* \brief Get the micro-frame number of USB device
@ -390,20 +372,14 @@ static inline uint16_t usb_device_get_frame_number(struct usb_module *module_ins
* \param module_inst Pointer to USB device module instance
* \return USB device micro-frame number value.
*/
static inline uint16_t usb_device_get_micro_frame_number(struct usb_module *module_inst)
{
return ((uint16_t)(module_inst->hw->DEVICE.FNUM.reg));
}
static inline uint16_t usb_device_get_micro_frame_number(struct usb_module *module_inst) { return ((uint16_t)(module_inst->hw->DEVICE.FNUM.reg)); }
/**
* \brief USB device send the resume wakeup
*
* \param module_inst Pointer to USB device module instance
*/
static inline void usb_device_send_remote_wake_up(struct usb_module *module_inst)
{
module_inst->hw->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_UPRSM;
}
static inline void usb_device_send_remote_wake_up(struct usb_module *module_inst) { module_inst->hw->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_UPRSM; }
/**
* \brief USB device set the LPM mode
@ -411,67 +387,45 @@ static inline void usb_device_send_remote_wake_up(struct usb_module *module_inst
* \param module_inst Pointer to USB device module instance
* \param lpm_mode LPM mode
*/
static inline void usb_device_set_lpm_mode(struct usb_module *module_inst,
enum usb_device_lpm_mode lpm_mode)
{
module_inst->hw->DEVICE.CTRLB.bit.LPMHDSK = lpm_mode;
}
static inline void usb_device_set_lpm_mode(struct usb_module *module_inst, enum usb_device_lpm_mode lpm_mode) { module_inst->hw->DEVICE.CTRLB.bit.LPMHDSK = lpm_mode; }
/**
* \name USB Device Callback Management
* @{
*/
enum status_code usb_device_register_callback(struct usb_module *module_inst,
enum usb_device_callback callback_type,
usb_device_callback_t callback_func);
enum status_code usb_device_unregister_callback(struct usb_module *module_inst,
enum usb_device_callback callback_type);
enum status_code usb_device_enable_callback(struct usb_module *module_inst,
enum usb_device_callback callback_type);
enum status_code usb_device_disable_callback(struct usb_module *module_inst,
enum usb_device_callback callback_type);
enum status_code usb_device_register_callback(struct usb_module *module_inst, enum usb_device_callback callback_type, usb_device_callback_t callback_func);
enum status_code usb_device_unregister_callback(struct usb_module *module_inst, enum usb_device_callback callback_type);
enum status_code usb_device_enable_callback(struct usb_module *module_inst, enum usb_device_callback callback_type);
enum status_code usb_device_disable_callback(struct usb_module *module_inst, enum usb_device_callback callback_type);
/** @} */
/**
* \name USB Device Endpoint Configuration
* @{
*/
void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *ep_config);
enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst,
struct usb_device_endpoint_config *ep_config);
bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t ep);
void usb_device_endpoint_get_config_defaults(struct usb_device_endpoint_config *ep_config);
enum status_code usb_device_endpoint_set_config(struct usb_module *module_inst, struct usb_device_endpoint_config *ep_config);
bool usb_device_endpoint_is_configured(struct usb_module *module_inst, uint8_t ep);
/** @} */
/**
* \name USB Device Endpoint Callback Management
* @{
*/
enum status_code usb_device_endpoint_register_callback(
struct usb_module *module_inst, uint8_t ep_num,
enum usb_device_endpoint_callback callback_type,
usb_device_endpoint_callback_t callback_func);
enum status_code usb_device_endpoint_unregister_callback(
struct usb_module *module_inst, uint8_t ep_num,
enum usb_device_endpoint_callback callback_type);
enum status_code usb_device_endpoint_enable_callback(
struct usb_module *module_inst, uint8_t ep,
enum usb_device_endpoint_callback callback_type);
enum status_code usb_device_endpoint_disable_callback(
struct usb_module *module_inst, uint8_t ep,
enum usb_device_endpoint_callback callback_type);
enum status_code usb_device_endpoint_register_callback(struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type, usb_device_endpoint_callback_t callback_func);
enum status_code usb_device_endpoint_unregister_callback(struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type);
enum status_code usb_device_endpoint_enable_callback(struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type);
enum status_code usb_device_endpoint_disable_callback(struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type);
/** @} */
/**
* \name USB Device Endpoint Job Management
* @{
*/
enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_inst,uint8_t ep_num,
uint8_t* pbuf, uint32_t buf_size);
enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_inst,uint8_t ep_num,
uint8_t* pbuf, uint32_t buf_size);
enum status_code usb_device_endpoint_setup_buffer_job(struct usb_module *module_inst,
uint8_t* pbuf);
void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep);
enum status_code usb_device_endpoint_write_buffer_job(struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size);
enum status_code usb_device_endpoint_read_buffer_job(struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size);
enum status_code usb_device_endpoint_setup_buffer_job(struct usb_module *module_inst, uint8_t *pbuf);
void usb_device_endpoint_abort_job(struct usb_module *module_inst, uint8_t ep);
/** @} */
/**

View file

@ -18,23 +18,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "arm_atsam_protocol.h"
#include <string.h>
Usb2422 USB2422_shadow;
Usb2422 USB2422_shadow;
unsigned char i2c0_buf[34];
const uint16_t MFRNAME[] = { 'M','a','s','s','d','r','o','p',' ','I','n','c','.' }; //Massdrop Inc.
const uint16_t PRDNAME[] = { 'M','a','s','s','d','r','o','p',' ','H','u','b' }; //Massdrop Hub
const uint16_t MFRNAME[] = {'M', 'a', 's', 's', 'd', 'r', 'o', 'p', ' ', 'I', 'n', 'c', '.'}; // Massdrop Inc.
const uint16_t PRDNAME[] = {'M', 'a', 's', 's', 'd', 'r', 'o', 'p', ' ', 'H', 'u', 'b'}; // Massdrop Hub
#ifndef MD_BOOTLOADER
//Serial number reported stops before first found space character or at last found character
const uint16_t SERNAME[] = { 'U','n','a','v','a','i','l','a','b','l','e' }; //Unavailable
// Serial number reported stops before first found space character or at last found character
const uint16_t SERNAME[] = {'U', 'n', 'a', 'v', 'a', 'i', 'l', 'a', 'b', 'l', 'e'}; // Unavailable
#else
//In production, this field is found, modified, and offset noted as the last 32-bit word in the bootloader space
//The offset allows the application to use the factory programmed serial (which may differ from the physical serial label)
//Serial number reported stops before first found space character or when max size is reached
__attribute__((__aligned__(4)))
const uint16_t SERNAME[BOOTLOADER_SERIAL_MAX_SIZE] = { 'M','D','H','U','B','B','O','O','T','L','0','0','0','0','0','0','0','0','0','0' };
//NOTE: Serial replacer will not write a string longer than given here as a precaution, so give enough
// In production, this field is found, modified, and offset noted as the last 32-bit word in the bootloader space
// The offset allows the application to use the factory programmed serial (which may differ from the physical serial label)
// Serial number reported stops before first found space character or when max size is reached
__attribute__((__aligned__(4))) const uint16_t SERNAME[BOOTLOADER_SERIAL_MAX_SIZE] = {'M', 'D', 'H', 'U', 'B', 'B', 'O', 'O', 'T', 'L', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'};
// NOTE: Serial replacer will not write a string longer than given here as a precaution, so give enough
// space as needed and adjust BOOTLOADER_SERIAL_MAX_SIZE to match amount given
#endif //MD_BOOTLOADER
#endif // MD_BOOTLOADER
uint8_t usb_host_port;
@ -44,95 +43,116 @@ uint8_t usb_extra_state;
uint8_t usb_extra_manual;
uint8_t usb_gcr_auto;
#endif //MD_BOOTLOADER
#endif // MD_BOOTLOADER
uint16_t adc_extra;
void USB_write2422_block(void)
{
void USB_write2422_block(void) {
unsigned char *dest = i2c0_buf;
unsigned char *src;
unsigned char *base = (unsigned char *)&USB2422_shadow;
DBGC(DC_USB_WRITE2422_BLOCK_BEGIN);
for (src = base; src < base + 256; src += 32)
{
for (src = base; src < base + 256; src += 32) {
dest[0] = src - base;
dest[1] = 32;
memcpy(&dest[2], src, 32);
i2c0_transmit(USB2422_ADDR, dest, 34, 50000);
SERCOM0->I2CM.CTRLB.bit.CMD = 0x03;
while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) { DBGC(DC_USB_WRITE2422_BLOCK_SYNC_SYSOP); }
while (SERCOM0->I2CM.SYNCBUSY.bit.SYSOP) {
DBGC(DC_USB_WRITE2422_BLOCK_SYNC_SYSOP);
}
wait_us(100);
}
DBGC(DC_USB_WRITE2422_BLOCK_COMPLETE);
}
void USB2422_init(void)
{
Gclk *pgclk = GCLK;
Mclk *pmclk = MCLK;
Port *pport = PORT;
Oscctrl *posc = OSCCTRL;
Usb *pusb = USB;
void USB2422_init(void) {
Gclk * pgclk = GCLK;
Mclk * pmclk = MCLK;
Port * pport = PORT;
Oscctrl *posc = OSCCTRL;
Usb * pusb = USB;
DBGC(DC_USB2422_INIT_BEGIN);
while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) { DBGC(DC_USB2422_INIT_WAIT_5V_LOW); }
while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) {
DBGC(DC_USB2422_INIT_WAIT_5V_LOW);
}
//setup peripheral and synchronous bus clocks to USB
pgclk->PCHCTRL[10].bit.GEN = 0;
// setup peripheral and synchronous bus clocks to USB
pgclk->PCHCTRL[10].bit.GEN = 0;
pgclk->PCHCTRL[10].bit.CHEN = 1;
pmclk->AHBMASK.bit.USB_ = 1;
pmclk->APBBMASK.bit.USB_ = 1;
pmclk->AHBMASK.bit.USB_ = 1;
pmclk->APBBMASK.bit.USB_ = 1;
//setup port pins for D-, D+, and SOF_1KHZ
pport->Group[0].PMUX[12].reg = 0x77; //PA24, PA25, function column H for USB D-, D+
// setup port pins for D-, D+, and SOF_1KHZ
pport->Group[0].PMUX[12].reg = 0x77; // PA24, PA25, function column H for USB D-, D+
pport->Group[0].PINCFG[24].bit.PMUXEN = 1;
pport->Group[0].PINCFG[25].bit.PMUXEN = 1;
pport->Group[1].PMUX[11].bit.PMUXE = 7; //PB22, function column H for USB SOF_1KHz output
pport->Group[1].PMUX[11].bit.PMUXE = 7; // PB22, function column H for USB SOF_1KHz output
pport->Group[1].PINCFG[22].bit.PMUXEN = 1;
//configure and enable DFLL for USB clock recovery mode at 48MHz
// configure and enable DFLL for USB clock recovery mode at 48MHz
posc->DFLLCTRLA.bit.ENABLE = 0;
while (posc->DFLLSYNC.bit.ENABLE) { DBGC(DC_USB2422_INIT_OSC_SYNC_DISABLING); }
while (posc->DFLLSYNC.bit.DFLLCTRLB) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_1); }
while (posc->DFLLSYNC.bit.ENABLE) {
DBGC(DC_USB2422_INIT_OSC_SYNC_DISABLING);
}
while (posc->DFLLSYNC.bit.DFLLCTRLB) {
DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_1);
}
posc->DFLLCTRLB.bit.USBCRM = 1;
while (posc->DFLLSYNC.bit.DFLLCTRLB) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_2); }
while (posc->DFLLSYNC.bit.DFLLCTRLB) {
DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_2);
}
posc->DFLLCTRLB.bit.MODE = 1;
while (posc->DFLLSYNC.bit.DFLLCTRLB) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_3); }
while (posc->DFLLSYNC.bit.DFLLCTRLB) {
DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_3);
}
posc->DFLLCTRLB.bit.QLDIS = 0;
while (posc->DFLLSYNC.bit.DFLLCTRLB) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_4); }
while (posc->DFLLSYNC.bit.DFLLCTRLB) {
DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_4);
}
posc->DFLLCTRLB.bit.CCDIS = 1;
posc->DFLLMUL.bit.MUL = 0xBB80; //4800 x 1KHz
while (posc->DFLLSYNC.bit.DFLLMUL) { DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLMUL); }
posc->DFLLMUL.bit.MUL = 0xBB80; // 4800 x 1KHz
while (posc->DFLLSYNC.bit.DFLLMUL) {
DBGC(DC_USB2422_INIT_OSC_SYNC_DFLLMUL);
}
posc->DFLLCTRLA.bit.ENABLE = 1;
while (posc->DFLLSYNC.bit.ENABLE) { DBGC(DC_USB2422_INIT_OSC_SYNC_ENABLING); }
while (posc->DFLLSYNC.bit.ENABLE) {
DBGC(DC_USB2422_INIT_OSC_SYNC_ENABLING);
}
pusb->DEVICE.CTRLA.bit.SWRST = 1;
while (pusb->DEVICE.SYNCBUSY.bit.SWRST) { DBGC(DC_USB2422_INIT_USB_SYNC_SWRST); }
while (pusb->DEVICE.CTRLA.bit.SWRST) { DBGC(DC_USB2422_INIT_USB_WAIT_SWRST); }
//calibration from factory presets
while (pusb->DEVICE.SYNCBUSY.bit.SWRST) {
DBGC(DC_USB2422_INIT_USB_SYNC_SWRST);
}
while (pusb->DEVICE.CTRLA.bit.SWRST) {
DBGC(DC_USB2422_INIT_USB_WAIT_SWRST);
}
// calibration from factory presets
pusb->DEVICE.PADCAL.bit.TRANSN = (USB_FUSES_TRANSN_ADDR >> USB_FUSES_TRANSN_Pos) & USB_FUSES_TRANSN_Msk;
pusb->DEVICE.PADCAL.bit.TRANSP = (USB_FUSES_TRANSP_ADDR >> USB_FUSES_TRANSP_Pos) & USB_FUSES_TRANSP_Msk;
pusb->DEVICE.PADCAL.bit.TRIM = (USB_FUSES_TRIM_ADDR >> USB_FUSES_TRIM_Pos) & USB_FUSES_TRIM_Msk;
//device mode, enabled
pusb->DEVICE.CTRLB.bit.SPDCONF = 0; //full speed
pusb->DEVICE.CTRLA.bit.MODE = 0;
pusb->DEVICE.CTRLA.bit.ENABLE = 1;
while (pusb->DEVICE.SYNCBUSY.bit.ENABLE) { DBGC(DC_USB2422_INIT_USB_SYNC_ENABLING); }
pusb->DEVICE.PADCAL.bit.TRIM = (USB_FUSES_TRIM_ADDR >> USB_FUSES_TRIM_Pos) & USB_FUSES_TRIM_Msk;
// device mode, enabled
pusb->DEVICE.CTRLB.bit.SPDCONF = 0; // full speed
pusb->DEVICE.CTRLA.bit.MODE = 0;
pusb->DEVICE.CTRLA.bit.ENABLE = 1;
while (pusb->DEVICE.SYNCBUSY.bit.ENABLE) {
DBGC(DC_USB2422_INIT_USB_SYNC_ENABLING);
}
pusb->DEVICE.QOSCTRL.bit.DQOS = 2;
pusb->DEVICE.QOSCTRL.bit.CQOS = 2;
pport->Group[USB2422_HUB_ACTIVE_GROUP].PINCFG[USB2422_HUB_ACTIVE_PIN].bit.INEN = 1;
i2c0_init(); //IC2 clk must be high at USB2422 reset release time to signal SMB configuration
i2c0_init(); // IC2 clk must be high at USB2422 reset release time to signal SMB configuration
sr_exp_data.bit.HUB_CONNECT = 1; //connect signal
sr_exp_data.bit.HUB_RESET_N = 1; //reset high
sr_exp_data.bit.HUB_CONNECT = 1; // connect signal
sr_exp_data.bit.HUB_RESET_N = 1; // reset high
SR_EXP_WriteData();
wait_us(100);
@ -140,78 +160,74 @@ void USB2422_init(void)
#ifndef MD_BOOTLOADER
usb_extra_manual = 0;
usb_gcr_auto = 1;
usb_gcr_auto = 1;
#endif //MD_BOOTLOADER
#endif // MD_BOOTLOADER
DBGC(DC_USB2422_INIT_COMPLETE);
}
void USB_reset(void)
{
void USB_reset(void) {
DBGC(DC_USB_RESET_BEGIN);
//pulse reset for at least 1 usec
sr_exp_data.bit.HUB_RESET_N = 0; //reset low
// pulse reset for at least 1 usec
sr_exp_data.bit.HUB_RESET_N = 0; // reset low
SR_EXP_WriteData();
wait_us(2);
sr_exp_data.bit.HUB_RESET_N = 1; //reset high to run
sr_exp_data.bit.HUB_RESET_N = 1; // reset high to run
SR_EXP_WriteData();
DBGC(DC_USB_RESET_COMPLETE);
}
void USB_configure(void)
{
void USB_configure(void) {
Usb2422 *pusb2422 = &USB2422_shadow;
memset(pusb2422, 0, sizeof(Usb2422));
uint16_t *serial_use = (uint16_t *)SERNAME; //Default to use SERNAME from this file
uint8_t serial_length = sizeof(SERNAME) / sizeof(uint16_t); //Default to use SERNAME from this file
uint16_t *serial_use = (uint16_t *)SERNAME; // Default to use SERNAME from this file
uint8_t serial_length = sizeof(SERNAME) / sizeof(uint16_t); // Default to use SERNAME from this file
#ifndef MD_BOOTLOADER
uint32_t serial_ptrloc = (uint32_t)&_srom - 4;
#else //MD_BOOTLOADER
#else // MD_BOOTLOADER
uint32_t serial_ptrloc = (uint32_t)&_erom - 4;
#endif //MD_BOOTLOADER
uint32_t serial_address = *(uint32_t *)serial_ptrloc; //Address of bootloader's serial number if available
#endif // MD_BOOTLOADER
uint32_t serial_address = *(uint32_t *)serial_ptrloc; // Address of bootloader's serial number if available
DBGC(DC_USB_CONFIGURE_BEGIN);
if (serial_address != 0xFFFFFFFF && serial_address < serial_ptrloc) //Check for factory programmed serial address
if (serial_address != 0xFFFFFFFF && serial_address < serial_ptrloc) // Check for factory programmed serial address
{
if ((serial_address & 0xFF) % 4 == 0) //Check alignment
if ((serial_address & 0xFF) % 4 == 0) // Check alignment
{
serial_use = (uint16_t *)(serial_address);
serial_use = (uint16_t *)(serial_address);
serial_length = 0;
while ((*(serial_use + serial_length) > 32 && *(serial_use + serial_length) < 127) &&
serial_length < BOOTLOADER_SERIAL_MAX_SIZE)
{
while ((*(serial_use + serial_length) > 32 && *(serial_use + serial_length) < 127) && serial_length < BOOTLOADER_SERIAL_MAX_SIZE) {
serial_length++;
DBGC(DC_USB_CONFIGURE_GET_SERIAL);
}
}
}
//configure Usb2422 registers
pusb2422->VID.reg = 0x04D8; // from Microchip 4/19/2018
pusb2422->PID.reg = 0xEEC5; // from Microchip 4/19/2018 = Massdrop, Inc. USB Hub
pusb2422->DID.reg = 0x0101; // BCD 01.01
pusb2422->CFG1.bit.SELF_BUS_PWR = 1; // self powered for now
pusb2422->CFG1.bit.HS_DISABLE = 1; // full or high speed
//pusb2422->CFG2.bit.COMPOUND = 0; // compound device
pusb2422->CFG3.bit.STRING_EN = 1; // strings enabled
//pusb2422->NRD.bit.PORT2_NR = 0; // MCU is non-removable
pusb2422->MAXPB.reg = 20; // 0mA
pusb2422->HCMCB.reg = 20; // 0mA
// configure Usb2422 registers
pusb2422->VID.reg = 0x04D8; // from Microchip 4/19/2018
pusb2422->PID.reg = 0xEEC5; // from Microchip 4/19/2018 = Massdrop, Inc. USB Hub
pusb2422->DID.reg = 0x0101; // BCD 01.01
pusb2422->CFG1.bit.SELF_BUS_PWR = 1; // self powered for now
pusb2422->CFG1.bit.HS_DISABLE = 1; // full or high speed
// pusb2422->CFG2.bit.COMPOUND = 0; // compound device
pusb2422->CFG3.bit.STRING_EN = 1; // strings enabled
// pusb2422->NRD.bit.PORT2_NR = 0; // MCU is non-removable
pusb2422->MAXPB.reg = 20; // 0mA
pusb2422->HCMCB.reg = 20; // 0mA
pusb2422->MFRSL.reg = sizeof(MFRNAME) / sizeof(uint16_t);
pusb2422->PRDSL.reg = sizeof(PRDNAME) / sizeof(uint16_t);
pusb2422->SERSL.reg = serial_length;
memcpy(pusb2422->MFRSTR, MFRNAME, sizeof(MFRNAME));
memcpy(pusb2422->PRDSTR, PRDNAME, sizeof(PRDNAME));
memcpy(pusb2422->SERSTR, serial_use, serial_length * sizeof(uint16_t));
//pusb2422->BOOSTUP.bit.BOOST=3; //upstream port
//pusb2422->BOOSTDOWN.bit.BOOST1=0; // extra port
//pusb2422->BOOSTDOWN.bit.BOOST2=2; //MCU is close
// pusb2422->BOOSTUP.bit.BOOST=3; //upstream port
// pusb2422->BOOSTDOWN.bit.BOOST1=0; // extra port
// pusb2422->BOOSTDOWN.bit.BOOST2=2; //MCU is close
pusb2422->STCD.bit.USB_ATTACH = 1;
USB_write2422_block();
@ -220,35 +236,33 @@ void USB_configure(void)
DBGC(DC_USB_CONFIGURE_COMPLETE);
}
uint16_t USB_active(void)
{
return (PORT->Group[USB2422_HUB_ACTIVE_GROUP].IN.reg & (1 << USB2422_HUB_ACTIVE_PIN)) != 0;
}
uint16_t USB_active(void) { return (PORT->Group[USB2422_HUB_ACTIVE_GROUP].IN.reg & (1 << USB2422_HUB_ACTIVE_PIN)) != 0; }
void USB_set_host_by_voltage(void)
{
//UP is upstream device (HOST)
//DN1 is downstream device (EXTRA)
//DN2 is keyboard (KEYB)
void USB_set_host_by_voltage(void) {
// UP is upstream device (HOST)
// DN1 is downstream device (EXTRA)
// DN2 is keyboard (KEYB)
DBGC(DC_USB_SET_HOST_BY_VOLTAGE_BEGIN);
usb_host_port = USB_HOST_PORT_UNKNOWN;
#ifndef MD_BOOTLOADER
usb_extra_state = USB_EXTRA_STATE_UNKNOWN;
#endif //MD_BOOTLOADER
sr_exp_data.bit.SRC_1 = 1; //USBC-1 available for test
sr_exp_data.bit.SRC_2 = 1; //USBC-2 available for test
sr_exp_data.bit.E_UP_N = 1; //HOST disable
sr_exp_data.bit.E_DN1_N = 1; //EXTRA disable
sr_exp_data.bit.E_VBUS_1 = 0; //USBC-1 disable full power I/O
sr_exp_data.bit.E_VBUS_2 = 0; //USBC-2 disable full power I/O
#endif // MD_BOOTLOADER
sr_exp_data.bit.SRC_1 = 1; // USBC-1 available for test
sr_exp_data.bit.SRC_2 = 1; // USBC-2 available for test
sr_exp_data.bit.E_UP_N = 1; // HOST disable
sr_exp_data.bit.E_DN1_N = 1; // EXTRA disable
sr_exp_data.bit.E_VBUS_1 = 0; // USBC-1 disable full power I/O
sr_exp_data.bit.E_VBUS_2 = 0; // USBC-2 disable full power I/O
SR_EXP_WriteData();
wait_ms(250);
while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) { DBGC(DC_USB_SET_HOST_5V_LOW_WAITING); }
while ((v_5v = adc_get(ADC_5V)) < ADC_5V_START_LEVEL) {
DBGC(DC_USB_SET_HOST_5V_LOW_WAITING);
}
v_con_1 = adc_get(ADC_CON1);
v_con_2 = adc_get(ADC_CON2);
@ -256,37 +270,34 @@ void USB_set_host_by_voltage(void)
v_con_1_boot = v_con_1;
v_con_2_boot = v_con_2;
if (v_con_1 > v_con_2)
{
sr_exp_data.bit.S_UP = 0; //HOST to USBC-1
sr_exp_data.bit.S_DN1 = 1; //EXTRA to USBC-2
sr_exp_data.bit.SRC_1 = 1; //HOST on USBC-1
sr_exp_data.bit.SRC_2 = 0; //EXTRA available on USBC-2
if (v_con_1 > v_con_2) {
sr_exp_data.bit.S_UP = 0; // HOST to USBC-1
sr_exp_data.bit.S_DN1 = 1; // EXTRA to USBC-2
sr_exp_data.bit.SRC_1 = 1; // HOST on USBC-1
sr_exp_data.bit.SRC_2 = 0; // EXTRA available on USBC-2
sr_exp_data.bit.E_VBUS_1 = 1; //USBC-1 enable full power I/O
sr_exp_data.bit.E_VBUS_2 = 0; //USBC-2 disable full power I/O
sr_exp_data.bit.E_VBUS_1 = 1; // USBC-1 enable full power I/O
sr_exp_data.bit.E_VBUS_2 = 0; // USBC-2 disable full power I/O
SR_EXP_WriteData();
sr_exp_data.bit.E_UP_N = 0; //HOST enable
sr_exp_data.bit.E_UP_N = 0; // HOST enable
SR_EXP_WriteData();
usb_host_port = USB_HOST_PORT_1;
}
else
{
sr_exp_data.bit.S_UP = 1; //EXTRA to USBC-1
sr_exp_data.bit.S_DN1 = 0; //HOST to USBC-2
sr_exp_data.bit.SRC_1 = 0; //EXTRA available on USBC-1
sr_exp_data.bit.SRC_2 = 1; //HOST on USBC-2
} else {
sr_exp_data.bit.S_UP = 1; // EXTRA to USBC-1
sr_exp_data.bit.S_DN1 = 0; // HOST to USBC-2
sr_exp_data.bit.SRC_1 = 0; // EXTRA available on USBC-1
sr_exp_data.bit.SRC_2 = 1; // HOST on USBC-2
sr_exp_data.bit.E_VBUS_1 = 0; //USBC-1 disable full power I/O
sr_exp_data.bit.E_VBUS_2 = 1; //USBC-2 enable full power I/O
sr_exp_data.bit.E_VBUS_1 = 0; // USBC-1 disable full power I/O
sr_exp_data.bit.E_VBUS_2 = 1; // USBC-2 enable full power I/O
SR_EXP_WriteData();
sr_exp_data.bit.E_UP_N = 0; //HOST enable
sr_exp_data.bit.E_UP_N = 0; // HOST enable
SR_EXP_WriteData();
@ -295,7 +306,7 @@ void USB_set_host_by_voltage(void)
#ifndef MD_BOOTLOADER
usb_extra_state = USB_EXTRA_STATE_DISABLED;
#endif //MD_BOOTLOADER
#endif // MD_BOOTLOADER
USB_reset();
USB_configure();
@ -303,8 +314,7 @@ void USB_set_host_by_voltage(void)
DBGC(DC_USB_SET_HOST_BY_VOLTAGE_COMPLETE);
}
uint8_t USB2422_Port_Detect_Init(void)
{
uint8_t USB2422_Port_Detect_Init(void) {
uint32_t port_detect_retry_ms;
uint32_t tmod;
@ -314,26 +324,30 @@ uint8_t USB2422_Port_Detect_Init(void)
port_detect_retry_ms = timer_read64() + PORT_DETECT_RETRY_INTERVAL;
while (!USB_active())
{
while (!USB_active()) {
tmod = timer_read64() % PORT_DETECT_RETRY_INTERVAL;
if (v_con_1 > v_con_2) //Values updated from USB_set_host_by_voltage();
if (v_con_1 > v_con_2) // Values updated from USB_set_host_by_voltage();
{
//1 flash for port 1 detected
if (tmod > 500 && tmod < 600) { DBG_LED_ON; }
else { DBG_LED_OFF; }
}
else if (v_con_2 > v_con_1) //Values updated from USB_set_host_by_voltage();
// 1 flash for port 1 detected
if (tmod > 500 && tmod < 600) {
DBG_LED_ON;
} else {
DBG_LED_OFF;
}
} else if (v_con_2 > v_con_1) // Values updated from USB_set_host_by_voltage();
{
//2 flash for port 2 detected
if (tmod > 500 && tmod < 600) { DBG_LED_ON; }
else if (tmod > 700 && tmod < 800) { DBG_LED_ON; }
else { DBG_LED_OFF; }
// 2 flash for port 2 detected
if (tmod > 500 && tmod < 600) {
DBG_LED_ON;
} else if (tmod > 700 && tmod < 800) {
DBG_LED_ON;
} else {
DBG_LED_OFF;
}
}
if (timer_read64() > port_detect_retry_ms)
{
if (timer_read64() > port_detect_retry_ms) {
DBGC(DC_PORT_DETECT_INIT_FAILED);
return 0;
}
@ -346,65 +360,67 @@ uint8_t USB2422_Port_Detect_Init(void)
#ifndef MD_BOOTLOADER
void USB_ExtraSetState(uint8_t state)
{
void USB_ExtraSetState(uint8_t state) {
uint8_t state_save = state;
if (state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG)
state = USB_EXTRA_STATE_DISABLED;
if (state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) state = USB_EXTRA_STATE_DISABLED;
if (usb_host_port == USB_HOST_PORT_1) sr_exp_data.bit.E_VBUS_2 = state;
else if (usb_host_port == USB_HOST_PORT_2) sr_exp_data.bit.E_VBUS_1 = state;
else return;
if (usb_host_port == USB_HOST_PORT_1)
sr_exp_data.bit.E_VBUS_2 = state;
else if (usb_host_port == USB_HOST_PORT_2)
sr_exp_data.bit.E_VBUS_1 = state;
else
return;
sr_exp_data.bit.E_DN1_N = !state;
SR_EXP_WriteData();
usb_extra_state = state_save;
if (usb_extra_state == USB_EXTRA_STATE_ENABLED) CDC_print("USB: Extra enabled\r\n");
else if (usb_extra_state == USB_EXTRA_STATE_DISABLED)
{
if (usb_extra_state == USB_EXTRA_STATE_ENABLED)
CDC_print("USB: Extra enabled\r\n");
else if (usb_extra_state == USB_EXTRA_STATE_DISABLED) {
CDC_print("USB: Extra disabled\r\n");
#ifdef USE_MASSDROP_CONFIGURATOR
# ifdef USE_MASSDROP_CONFIGURATOR
if (led_animation_breathing) gcr_breathe = gcr_desired;
#endif
}
else if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) CDC_print("USB: Extra disabled until replug\r\n");
else CDC_print("USB: Extra state unknown\r\n");
# endif
} else if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG)
CDC_print("USB: Extra disabled until replug\r\n");
else
CDC_print("USB: Extra state unknown\r\n");
}
void USB_HandleExtraDevice(void)
{
void USB_HandleExtraDevice(void) {
uint16_t adcval;
if (usb_host_port == USB_HOST_PORT_1) adcval = adc_get(ADC_CON2);
else if (usb_host_port == USB_HOST_PORT_2) adcval = adc_get(ADC_CON1);
else return;
if (usb_host_port == USB_HOST_PORT_1)
adcval = adc_get(ADC_CON2);
else if (usb_host_port == USB_HOST_PORT_2)
adcval = adc_get(ADC_CON1);
else
return;
adc_extra = adc_extra * 0.9 + adcval * 0.1;
//Check for a forced disable state (such as overload prevention)
if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG)
{
//Detect unplug and reset state to disabled
// Check for a forced disable state (such as overload prevention)
if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) {
// Detect unplug and reset state to disabled
if (adc_extra > USB_EXTRA_ADC_THRESHOLD) usb_extra_state = USB_EXTRA_STATE_DISABLED;
return; //Return even if unplug detected
return; // Return even if unplug detected
}
if (usb_extra_manual)
{
if (usb_extra_state == USB_EXTRA_STATE_DISABLED)
USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
if (usb_extra_manual) {
if (usb_extra_state == USB_EXTRA_STATE_DISABLED) USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
return;
}
//dpf("a %i %i\r\n",adcval, adc_extra);
if (usb_extra_state == USB_EXTRA_STATE_DISABLED && adc_extra < USB_EXTRA_ADC_THRESHOLD) USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
else if (usb_extra_state == USB_EXTRA_STATE_ENABLED && adc_extra > USB_EXTRA_ADC_THRESHOLD) USB_ExtraSetState(USB_EXTRA_STATE_DISABLED);
// dpf("a %i %i\r\n",adcval, adc_extra);
if (usb_extra_state == USB_EXTRA_STATE_DISABLED && adc_extra < USB_EXTRA_ADC_THRESHOLD)
USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
else if (usb_extra_state == USB_EXTRA_STATE_ENABLED && adc_extra > USB_EXTRA_ADC_THRESHOLD)
USB_ExtraSetState(USB_EXTRA_STATE_DISABLED);
}
#endif //MD_BOOTLOADER
#endif // MD_BOOTLOADER

View file

@ -18,226 +18,225 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _USB2422_H_
#define _USB2422_H_
#define REV_USB2422 0x100
#define REV_USB2422 0x100
#define USB2422_ADDR 0x58 //I2C device address, one instance
#define USB2422_ADDR 0x58 // I2C device address, one instance
#define USB2422_HUB_ACTIVE_GROUP 0 //PA
#define USB2422_HUB_ACTIVE_PIN 18 //18
#define USB2422_HUB_ACTIVE_GROUP 0 // PA
#define USB2422_HUB_ACTIVE_PIN 18 // 18
/* -------- USB2422_VID : (USB2422L Offset: 0x00) (R/W 16) Vendor ID -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint16_t VID_LSB : 8;
uint16_t VID_MSB : 8;
} bit; /*!< Structure used for bit access */
uint16_t reg; /*!< Type used for register access */
struct {
uint16_t VID_LSB : 8;
uint16_t VID_MSB : 8;
} bit; /*!< Structure used for bit access */
uint16_t reg; /*!< Type used for register access */
} USB2422_VID_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_PID : (USB2422L Offset: 0x02) (R/W 16) Product ID -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint16_t PID_LSB : 8;
uint16_t PID_MSB : 8;
} bit; /*!< Structure used for bit access */
uint16_t reg; /*!< Type used for register access */
struct {
uint16_t PID_LSB : 8;
uint16_t PID_MSB : 8;
} bit; /*!< Structure used for bit access */
uint16_t reg; /*!< Type used for register access */
} USB2422_PID_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_DID : (USB2422L Offset: 0x04) (R/W 16) Device ID -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint16_t DID_LSB : 8;
uint16_t DID_MSB : 8;
} bit; /*!< Structure used for bit access */
uint16_t reg; /*!< Type used for register access */
struct {
uint16_t DID_LSB : 8;
uint16_t DID_MSB : 8;
} bit; /*!< Structure used for bit access */
uint16_t reg; /*!< Type used for register access */
} USB2422_DID_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_CFG1 : (USB2422L Offset: 0x06) (R/W 8) Configuration Data Byte 1-------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t PORT_PWR : 1;
uint8_t CURRENT_SNS : 2;
uint8_t EOP_DISABLE : 1;
uint8_t MTT_ENABLE : 1;
uint8_t HS_DISABLE :1;
uint8_t :1;
uint8_t SELF_BUS_PWR : 1;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t PORT_PWR : 1;
uint8_t CURRENT_SNS : 2;
uint8_t EOP_DISABLE : 1;
uint8_t MTT_ENABLE : 1;
uint8_t HS_DISABLE : 1;
uint8_t : 1;
uint8_t SELF_BUS_PWR : 1;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_CFG1_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_CFG2 : (USB2422L Offset: 0x07) (R/W 8) Configuration Data Byte 2-------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t : 3;
uint8_t COMPOUND : 1;
uint8_t OC_TIMER :2;
uint8_t :1;
uint8_t DYNAMIC : 1;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t : 3;
uint8_t COMPOUND : 1;
uint8_t OC_TIMER : 2;
uint8_t : 1;
uint8_t DYNAMIC : 1;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_CFG2_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_CFG3 : (USB2422L Offset: 0x08) (R/W 16) Configuration Data Byte 3-------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t STRING_EN : 1;
uint8_t :2;
uint8_t PRTMAP_EN :1;
uint8_t : 4;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t STRING_EN : 1;
uint8_t : 2;
uint8_t PRTMAP_EN : 1;
uint8_t : 4;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_CFG3_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_NRD : (USB2422L Offset: 0x09) (R/W 8) Non Removable Device -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t : 5;
uint8_t PORT2_NR :1;
uint8_t PORT1_NR :1;
uint8_t : 1;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t : 5;
uint8_t PORT2_NR : 1;
uint8_t PORT1_NR : 1;
uint8_t : 1;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_NRD_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_PDS : (USB2422L Offset: 0x0A) (R/W 8) Port Diable for Self-Powered Operation -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t : 1;
uint8_t PORT1_DIS :1;
uint8_t PORT2_DIS :1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t : 1;
uint8_t PORT1_DIS : 1;
uint8_t PORT2_DIS : 1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_PDS_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_PDB : (USB2422L Offset: 0x0B) (R/W 8) Port Diable for Bus-Powered Operation -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t : 1;
uint8_t PORT1_DIS :1;
uint8_t PORT2_DIS :1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t : 1;
uint8_t PORT1_DIS : 1;
uint8_t PORT2_DIS : 1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_PDB_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_MAXPS : (USB2422L Offset: 0x0C) (R/W 8) Max Power for Self-Powered Operation -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t MAX_PWR_SP : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t MAX_PWR_SP : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_MAXPS_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_MAXPB : (USB2422L Offset: 0x0D) (R/W 8) Max Power for Bus-Powered Operation -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t MAX_PWR_BP : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t MAX_PWR_BP : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_MAXPB_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_HCMCS : (USB2422L Offset: 0x0E) (R/W 8) Hub Controller Max Current for Self-Powered Operation -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t HC_MAX_C_SP : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t HC_MAX_C_SP : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_HCMCS_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_HCMCB : (USB2422L Offset: 0x0F) (R/W 8) Hub Controller Max Current for Bus-Powered Operation -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t HC_MAX_C_BP : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t HC_MAX_C_BP : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_HCMCB_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_PWRT : (USB2422L Offset: 0x10) (R/W 8) Power On Time -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t POWER_ON_TIME : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t POWER_ON_TIME : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_PWRT_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_LANGID LSB : (USB2422L Offset: 0x11) (R/W 16) Language ID -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t LANGID_LSB : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t LANGID_LSB : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_LANGID_LSB_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_LANGID MSB : (USB2422L Offset: 0x12) (R/W 16) Language ID -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t LANGID_MSB : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t LANGID_MSB : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_LANGID_MSB_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_MFRSL : (USB2422L Offset: 0x13) (R/W 8) Manufacturer String Length -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t MFR_STR_LEN : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t MFR_STR_LEN : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_MFRSL_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_PRDSL : (USB2422L Offset: 0x14) (R/W 8) Product String Length -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t PRD_STR_LEN : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t PRD_STR_LEN : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_PRDSL_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_SERSL : (USB2422L Offset: 0x15) (R/W 8) Serial String Length -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t SER_STR_LEN : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t SER_STR_LEN : 8;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_SERSL_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
@ -259,60 +258,60 @@ typedef uint16_t USB2422_SERSTR_Type;
/* -------- USB2422_BCEN : (USB2422L Offset: 0xD0) (R/W 8) Battery Charging Enable -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t : 1;
uint8_t PORT1_BCE :1;
uint8_t PORT2_BCE :1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t : 1;
uint8_t PORT1_BCE : 1;
uint8_t PORT2_BCE : 1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_BCEN_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_BOOSTUP : (USB2422L Offset: 0xF6) (R/W 8) Boost Upstream -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t BOOST :2;
uint8_t : 6;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t BOOST : 2;
uint8_t : 6;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_BOOSTUP_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_BOOSTDOWN : (USB2422L Offset: 0xF8) (R/W 8) Boost Downstream -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t BOOST1 :2;
uint8_t BOOST2 :2;
uint8_t : 4;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t BOOST1 : 2;
uint8_t BOOST2 : 2;
uint8_t : 4;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_BOOSTDOWN_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_PRTSP : (USB2422L Offset: 0xFA) (R/W 8) Port Swap -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t : 1;
uint8_t PORT1_SP :1;
uint8_t PORT2_SP :1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t : 1;
uint8_t PORT1_SP : 1;
uint8_t PORT2_SP : 1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_PRTSP_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/* -------- USB2422_PRTR12 : (USB2422L Offset: 0xFB) (R/W 8) Port 1/2 Remap -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t PORT1_REMAP: 4;
uint8_t PORT2_REMAP: 4;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t PORT1_REMAP : 4;
uint8_t PORT2_REMAP : 4;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_PRTR12_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
#define USB2422_PRTR12_DISABLE 0
@ -324,81 +323,80 @@ typedef union {
/* -------- USB2422_STCD : (USB2422L Offset: 0xFF) (R/W 8) Status Command -------- */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef union {
struct {
uint8_t USB_ATTACH: 1;
uint8_t RESET: 1;
uint8_t INTF_PWRDN: 1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
struct {
uint8_t USB_ATTACH : 1;
uint8_t RESET : 1;
uint8_t INTF_PWRDN : 1;
uint8_t : 5;
} bit; /*!< Structure used for bit access */
uint8_t reg; /*!< Type used for register access */
} USB2422_STCD_Type;
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
/** \brief USB2422 device hardware registers */
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
typedef struct {
USB2422_VID_Type VID; /**< \brief Offset: 0x00*/
USB2422_PID_Type PID; /**< \brief Offset: 0x02*/
USB2422_DID_Type DID; /**< \brief Offset: 0x04*/
USB2422_CFG1_Type CFG1; /**< \brief Offset: 0x06*/
USB2422_CFG2_Type CFG2; /**< \brief Offset: 0x07*/
USB2422_CFG3_Type CFG3; /**< \brief Offset: 0x08*/
USB2422_NRD_Type NRD; /**< \brief Offset: 0x09*/
USB2422_PDS_Type PDS; /**< \brief Offset: 0x0A*/
USB2422_PDB_Type PDB; /**< \brief Offset: 0x0B*/
USB2422_MAXPS_Type MAXPS; /**< \brief Offset: 0x0C*/
USB2422_MAXPB_Type MAXPB; /**< \brief Offset: 0x0D*/
USB2422_HCMCS_Type HCMCS; /**< \brief Offset: 0x0E*/
USB2422_HCMCB_Type HCMCB; /**< \brief Offset: 0x0F*/
USB2422_PWRT_Type PWRT; /**< \brief Offset: 0x10*/
USB2422_LANGID_LSB_Type LANGID_LSB; /**< \brief Offset: 0x11*/
USB2422_LANGID_MSB_Type LANGID_MSB; /**< \brief Offset: 0x12*/
USB2422_MFRSL_Type MFRSL; /**< \brief Offset: 0x13*/
USB2422_PRDSL_Type PRDSL; /**< \brief Offset: 0x14*/
USB2422_SERSL_Type SERSL; /**< \brief Offset: 0x15*/
USB2422_MFRSTR_Type MFRSTR[31]; /**< \brief Offset: 0x16*/
USB2422_PRDSTR_Type PRDSTR[31]; /**< \brief Offset: 0x54*/
USB2422_SERSTR_Type SERSTR[31]; /**< \brief Offset: 0x92*/
USB2422_BCEN_Type BCEN; /**< \brief Offset: 0xD0*/
uint8_t Reserved1[0x25];
USB2422_BOOSTUP_Type BOOSTUP; /**< \brief Offset: 0xF6*/
uint8_t Reserved2[0x1];
USB2422_BOOSTDOWN_Type BOOSTDOWN; /**< \brief Offset: 0xF8*/
uint8_t Reserved3[0x1];
USB2422_PRTSP_Type PRTSP; /**< \brief Offset: 0xFA*/
USB2422_PRTR12_Type PRTR12; /**< \brief Offset: 0xFB*/
uint8_t Reserved4[0x3];
USB2422_STCD_Type STCD; /**< \brief Offset: 0xFF*/
USB2422_VID_Type VID; /**< \brief Offset: 0x00*/
USB2422_PID_Type PID; /**< \brief Offset: 0x02*/
USB2422_DID_Type DID; /**< \brief Offset: 0x04*/
USB2422_CFG1_Type CFG1; /**< \brief Offset: 0x06*/
USB2422_CFG2_Type CFG2; /**< \brief Offset: 0x07*/
USB2422_CFG3_Type CFG3; /**< \brief Offset: 0x08*/
USB2422_NRD_Type NRD; /**< \brief Offset: 0x09*/
USB2422_PDS_Type PDS; /**< \brief Offset: 0x0A*/
USB2422_PDB_Type PDB; /**< \brief Offset: 0x0B*/
USB2422_MAXPS_Type MAXPS; /**< \brief Offset: 0x0C*/
USB2422_MAXPB_Type MAXPB; /**< \brief Offset: 0x0D*/
USB2422_HCMCS_Type HCMCS; /**< \brief Offset: 0x0E*/
USB2422_HCMCB_Type HCMCB; /**< \brief Offset: 0x0F*/
USB2422_PWRT_Type PWRT; /**< \brief Offset: 0x10*/
USB2422_LANGID_LSB_Type LANGID_LSB; /**< \brief Offset: 0x11*/
USB2422_LANGID_MSB_Type LANGID_MSB; /**< \brief Offset: 0x12*/
USB2422_MFRSL_Type MFRSL; /**< \brief Offset: 0x13*/
USB2422_PRDSL_Type PRDSL; /**< \brief Offset: 0x14*/
USB2422_SERSL_Type SERSL; /**< \brief Offset: 0x15*/
USB2422_MFRSTR_Type MFRSTR[31]; /**< \brief Offset: 0x16*/
USB2422_PRDSTR_Type PRDSTR[31]; /**< \brief Offset: 0x54*/
USB2422_SERSTR_Type SERSTR[31]; /**< \brief Offset: 0x92*/
USB2422_BCEN_Type BCEN; /**< \brief Offset: 0xD0*/
uint8_t Reserved1[0x25];
USB2422_BOOSTUP_Type BOOSTUP; /**< \brief Offset: 0xF6*/
uint8_t Reserved2[0x1];
USB2422_BOOSTDOWN_Type BOOSTDOWN; /**< \brief Offset: 0xF8*/
uint8_t Reserved3[0x1];
USB2422_PRTSP_Type PRTSP; /**< \brief Offset: 0xFA*/
USB2422_PRTR12_Type PRTR12; /**< \brief Offset: 0xFB*/
uint8_t Reserved4[0x3];
USB2422_STCD_Type STCD; /**< \brief Offset: 0xFF*/
} Usb2422;
#endif
#define PORT_DETECT_RETRY_INTERVAL 2000
#define PORT_DETECT_RETRY_INTERVAL 2000
#define USB_EXTRA_ADC_THRESHOLD 900
#define USB_EXTRA_ADC_THRESHOLD 900
#define USB_EXTRA_STATE_DISABLED 0
#define USB_EXTRA_STATE_ENABLED 1
#define USB_EXTRA_STATE_UNKNOWN 2
#define USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG 3
#define USB_EXTRA_STATE_DISABLED 0
#define USB_EXTRA_STATE_ENABLED 1
#define USB_EXTRA_STATE_UNKNOWN 2
#define USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG 3
#define USB_HOST_PORT_1 0
#define USB_HOST_PORT_2 1
#define USB_HOST_PORT_UNKNOWN 2
#define USB_HOST_PORT_1 0
#define USB_HOST_PORT_2 1
#define USB_HOST_PORT_UNKNOWN 2
extern uint8_t usb_host_port;
extern uint8_t usb_extra_state;
extern uint8_t usb_extra_manual;
extern uint8_t usb_gcr_auto;
void USB2422_init(void);
void USB_reset(void);
void USB_configure(void);
void USB2422_init(void);
void USB_reset(void);
void USB_configure(void);
uint16_t USB_active(void);
void USB_set_host_by_voltage(void);
void USB_set_host_by_voltage(void);
uint16_t adc_get(uint8_t muxpos);
uint8_t USB2422_Port_Detect_Init(void);
void USB_HandleExtraDevice(void);
void USB_ExtraSetState(uint8_t state);
#endif //_USB2422_H_
uint8_t USB2422_Port_Detect_Init(void);
void USB_HandleExtraDevice(void);
void USB_ExtraSetState(uint8_t state);
#endif //_USB2422_H_

View file

@ -67,118 +67,118 @@
*/
//! \name Vendor Identifier assigned by USB org to ATMEL
#define USB_VID_ATMEL 0x03EB
#define USB_VID_ATMEL 0x03EB
//! \name Product Identifier assigned by ATMEL to AVR applications
//! @{
//! \name The range from 2000h to 20FFh is reserved to the old PID for C51, MEGA, and others.
//! @{
#define USB_PID_ATMEL_MEGA_HIDGENERIC 0x2013
#define USB_PID_ATMEL_MEGA_HIDKEYBOARD 0x2017
#define USB_PID_ATMEL_MEGA_CDC 0x2018
#define USB_PID_ATMEL_MEGA_AUDIO_IN 0x2019
#define USB_PID_ATMEL_MEGA_MS 0x201A
#define USB_PID_ATMEL_MEGA_AUDIO_IN_OUT 0x201B
#define USB_PID_ATMEL_MEGA_HIDMOUSE 0x201C
#define USB_PID_ATMEL_MEGA_HIDMOUSE_CERTIF_U4 0x201D
#define USB_PID_ATMEL_MEGA_CDC_MULTI 0x201E
#define USB_PID_ATMEL_MEGA_MS_HIDMS_HID_USBKEY 0x2022
#define USB_PID_ATMEL_MEGA_MS_HIDMS_HID_STK525 0x2023
#define USB_PID_ATMEL_MEGA_MS_2 0x2029
#define USB_PID_ATMEL_MEGA_MS_HIDMS 0x202A
#define USB_PID_ATMEL_MEGA_MS_3 0x2032
#define USB_PID_ATMEL_MEGA_LIBUSB 0x2050
#define USB_PID_ATMEL_MEGA_HIDGENERIC 0x2013
#define USB_PID_ATMEL_MEGA_HIDKEYBOARD 0x2017
#define USB_PID_ATMEL_MEGA_CDC 0x2018
#define USB_PID_ATMEL_MEGA_AUDIO_IN 0x2019
#define USB_PID_ATMEL_MEGA_MS 0x201A
#define USB_PID_ATMEL_MEGA_AUDIO_IN_OUT 0x201B
#define USB_PID_ATMEL_MEGA_HIDMOUSE 0x201C
#define USB_PID_ATMEL_MEGA_HIDMOUSE_CERTIF_U4 0x201D
#define USB_PID_ATMEL_MEGA_CDC_MULTI 0x201E
#define USB_PID_ATMEL_MEGA_MS_HIDMS_HID_USBKEY 0x2022
#define USB_PID_ATMEL_MEGA_MS_HIDMS_HID_STK525 0x2023
#define USB_PID_ATMEL_MEGA_MS_2 0x2029
#define USB_PID_ATMEL_MEGA_MS_HIDMS 0x202A
#define USB_PID_ATMEL_MEGA_MS_3 0x2032
#define USB_PID_ATMEL_MEGA_LIBUSB 0x2050
//! @}
//! \name The range 2100h to 21FFh is reserved to PIDs for AVR Tools.
//! @{
#define USB_PID_ATMEL_XPLAINED 0x2122
#define USB_PID_ATMEL_XMEGA_USB_ZIGBIT_2_4GHZ 0x214A
#define USB_PID_ATMEL_XMEGA_USB_ZIGBIT_SUBGHZ 0x214B
#define USB_PID_ATMEL_XPLAINED 0x2122
#define USB_PID_ATMEL_XMEGA_USB_ZIGBIT_2_4GHZ 0x214A
#define USB_PID_ATMEL_XMEGA_USB_ZIGBIT_SUBGHZ 0x214B
//! @}
//! \name The range 2300h to 23FFh is reserved to PIDs for demo from ASF1.7=>
//! @{
#define USB_PID_ATMEL_UC3_ENUM 0x2300
#define USB_PID_ATMEL_UC3_MS 0x2301
#define USB_PID_ATMEL_UC3_MS_SDRAM_LOADER 0x2302
#define USB_PID_ATMEL_UC3_EVK1100_CTRLPANEL 0x2303
#define USB_PID_ATMEL_UC3_HID 0x2304
#define USB_PID_ATMEL_UC3_EVK1101_CTRLPANEL_HID 0x2305
#define USB_PID_ATMEL_UC3_EVK1101_CTRLPANEL_HID_MS 0x2306
#define USB_PID_ATMEL_UC3_CDC 0x2307
#define USB_PID_ATMEL_UC3_AUDIO_MICRO 0x2308
#define USB_PID_ATMEL_UC3_CDC_DEBUG 0x2310 // Virtual Com (debug interface) on EVK11xx
#define USB_PID_ATMEL_UC3_AUDIO_SPEAKER_MICRO 0x2311
#define USB_PID_ATMEL_UC3_CDC_MSC 0x2312
#define USB_PID_ATMEL_UC3_ENUM 0x2300
#define USB_PID_ATMEL_UC3_MS 0x2301
#define USB_PID_ATMEL_UC3_MS_SDRAM_LOADER 0x2302
#define USB_PID_ATMEL_UC3_EVK1100_CTRLPANEL 0x2303
#define USB_PID_ATMEL_UC3_HID 0x2304
#define USB_PID_ATMEL_UC3_EVK1101_CTRLPANEL_HID 0x2305
#define USB_PID_ATMEL_UC3_EVK1101_CTRLPANEL_HID_MS 0x2306
#define USB_PID_ATMEL_UC3_CDC 0x2307
#define USB_PID_ATMEL_UC3_AUDIO_MICRO 0x2308
#define USB_PID_ATMEL_UC3_CDC_DEBUG 0x2310 // Virtual Com (debug interface) on EVK11xx
#define USB_PID_ATMEL_UC3_AUDIO_SPEAKER_MICRO 0x2311
#define USB_PID_ATMEL_UC3_CDC_MSC 0x2312
//! @}
//! \name The range 2400h to 24FFh is reserved to PIDs for ASF applications
//! @{
#define USB_PID_ATMEL_ASF_HIDMOUSE 0x2400
#define USB_PID_ATMEL_ASF_HIDKEYBOARD 0x2401
#define USB_PID_ATMEL_ASF_HIDGENERIC 0x2402
#define USB_PID_ATMEL_ASF_MSC 0x2403
#define USB_PID_ATMEL_ASF_CDC 0x2404
#define USB_PID_ATMEL_ASF_PHDC 0x2405
#define USB_PID_ATMEL_ASF_HIDMTOUCH 0x2406
#define USB_PID_ATMEL_ASF_MSC_HIDMOUSE 0x2420
#define USB_PID_ATMEL_ASF_MSC_HIDS_CDC 0x2421
#define USB_PID_ATMEL_ASF_MSC_HIDKEYBOARD 0x2422
#define USB_PID_ATMEL_ASF_VENDOR_CLASS 0x2423
#define USB_PID_ATMEL_ASF_MSC_CDC 0x2424
#define USB_PID_ATMEL_ASF_TWO_CDC 0x2425
#define USB_PID_ATMEL_ASF_SEVEN_CDC 0x2426
#define USB_PID_ATMEL_ASF_XPLAIN_BC_POWERONLY 0x2430
#define USB_PID_ATMEL_ASF_XPLAIN_BC_TERMINAL 0x2431
#define USB_PID_ATMEL_ASF_XPLAIN_BC_TOUCH 0x2432
#define USB_PID_ATMEL_ASF_AUDIO_SPEAKER 0x2433
#define USB_PID_ATMEL_ASF_XMEGA_B1_XPLAINED 0x2434
#define USB_PID_ATMEL_ASF_HIDMOUSE 0x2400
#define USB_PID_ATMEL_ASF_HIDKEYBOARD 0x2401
#define USB_PID_ATMEL_ASF_HIDGENERIC 0x2402
#define USB_PID_ATMEL_ASF_MSC 0x2403
#define USB_PID_ATMEL_ASF_CDC 0x2404
#define USB_PID_ATMEL_ASF_PHDC 0x2405
#define USB_PID_ATMEL_ASF_HIDMTOUCH 0x2406
#define USB_PID_ATMEL_ASF_MSC_HIDMOUSE 0x2420
#define USB_PID_ATMEL_ASF_MSC_HIDS_CDC 0x2421
#define USB_PID_ATMEL_ASF_MSC_HIDKEYBOARD 0x2422
#define USB_PID_ATMEL_ASF_VENDOR_CLASS 0x2423
#define USB_PID_ATMEL_ASF_MSC_CDC 0x2424
#define USB_PID_ATMEL_ASF_TWO_CDC 0x2425
#define USB_PID_ATMEL_ASF_SEVEN_CDC 0x2426
#define USB_PID_ATMEL_ASF_XPLAIN_BC_POWERONLY 0x2430
#define USB_PID_ATMEL_ASF_XPLAIN_BC_TERMINAL 0x2431
#define USB_PID_ATMEL_ASF_XPLAIN_BC_TOUCH 0x2432
#define USB_PID_ATMEL_ASF_AUDIO_SPEAKER 0x2433
#define USB_PID_ATMEL_ASF_XMEGA_B1_XPLAINED 0x2434
//! @}
//! \name The range 2F00h to 2FFFh is reserved to official PIDs for AVR bootloaders
//! Note, !!!! don't use this range for demos or examples !!!!
//! @{
#define USB_PID_ATMEL_DFU_ATXMEGA64C3 0x2FD6
#define USB_PID_ATMEL_DFU_ATXMEGA128C3 0x2FD7
#define USB_PID_ATMEL_DFU_ATXMEGA16C4 0x2FD8
#define USB_PID_ATMEL_DFU_ATXMEGA32C4 0x2FD9
#define USB_PID_ATMEL_DFU_ATXMEGA256C3 0x2FDA
#define USB_PID_ATMEL_DFU_ATXMEGA384C3 0x2FDB
#define USB_PID_ATMEL_DFU_ATUCL3_L4 0x2FDC
#define USB_PID_ATMEL_DFU_ATXMEGA64A4U 0x2FDD
#define USB_PID_ATMEL_DFU_ATXMEGA128A4U 0x2FDE
#define USB_PID_ATMEL_DFU_ATXMEGA64C3 0x2FD6
#define USB_PID_ATMEL_DFU_ATXMEGA128C3 0x2FD7
#define USB_PID_ATMEL_DFU_ATXMEGA16C4 0x2FD8
#define USB_PID_ATMEL_DFU_ATXMEGA32C4 0x2FD9
#define USB_PID_ATMEL_DFU_ATXMEGA256C3 0x2FDA
#define USB_PID_ATMEL_DFU_ATXMEGA384C3 0x2FDB
#define USB_PID_ATMEL_DFU_ATUCL3_L4 0x2FDC
#define USB_PID_ATMEL_DFU_ATXMEGA64A4U 0x2FDD
#define USB_PID_ATMEL_DFU_ATXMEGA128A4U 0x2FDE
#define USB_PID_ATMEL_DFU_ATXMEGA64B3 0x2FDF
#define USB_PID_ATMEL_DFU_ATXMEGA128B3 0x2FE0
#define USB_PID_ATMEL_DFU_ATXMEGA64B1 0x2FE1
#define USB_PID_ATMEL_DFU_ATXMEGA256A3BU 0x2FE2
#define USB_PID_ATMEL_DFU_ATXMEGA16A4U 0x2FE3
#define USB_PID_ATMEL_DFU_ATXMEGA32A4U 0x2FE4
#define USB_PID_ATMEL_DFU_ATXMEGA64A3U 0x2FE5
#define USB_PID_ATMEL_DFU_ATXMEGA128A3U 0x2FE6
#define USB_PID_ATMEL_DFU_ATXMEGA192A3U 0x2FE7
#define USB_PID_ATMEL_DFU_ATXMEGA64A1U 0x2FE8
#define USB_PID_ATMEL_DFU_ATUC3D 0x2FE9
#define USB_PID_ATMEL_DFU_ATXMEGA128B1 0x2FEA
#define USB_PID_ATMEL_DFU_AT32UC3C 0x2FEB
#define USB_PID_ATMEL_DFU_ATXMEGA256A3U 0x2FEC
#define USB_PID_ATMEL_DFU_ATXMEGA128A1U 0x2FED
#define USB_PID_ATMEL_DFU_ATMEGA8U2 0x2FEE
#define USB_PID_ATMEL_DFU_ATMEGA16U2 0x2FEF
#define USB_PID_ATMEL_DFU_ATMEGA32U2 0x2FF0
#define USB_PID_ATMEL_DFU_AT32UC3A3 0x2FF1
#define USB_PID_ATMEL_DFU_ATMEGA32U6 0x2FF2
#define USB_PID_ATMEL_DFU_ATMEGA16U4 0x2FF3
#define USB_PID_ATMEL_DFU_ATMEGA32U4 0x2FF4
#define USB_PID_ATMEL_DFU_AT32AP7200 0x2FF5
#define USB_PID_ATMEL_DFU_AT32UC3B 0x2FF6
#define USB_PID_ATMEL_DFU_AT90USB82 0x2FF7
#define USB_PID_ATMEL_DFU_AT32UC3A 0x2FF8
#define USB_PID_ATMEL_DFU_AT90USB64 0x2FF9
#define USB_PID_ATMEL_DFU_AT90USB162 0x2FFA
#define USB_PID_ATMEL_DFU_AT90USB128 0x2FFB
#define USB_PID_ATMEL_DFU_ATXMEGA64B3 0x2FDF
#define USB_PID_ATMEL_DFU_ATXMEGA128B3 0x2FE0
#define USB_PID_ATMEL_DFU_ATXMEGA64B1 0x2FE1
#define USB_PID_ATMEL_DFU_ATXMEGA256A3BU 0x2FE2
#define USB_PID_ATMEL_DFU_ATXMEGA16A4U 0x2FE3
#define USB_PID_ATMEL_DFU_ATXMEGA32A4U 0x2FE4
#define USB_PID_ATMEL_DFU_ATXMEGA64A3U 0x2FE5
#define USB_PID_ATMEL_DFU_ATXMEGA128A3U 0x2FE6
#define USB_PID_ATMEL_DFU_ATXMEGA192A3U 0x2FE7
#define USB_PID_ATMEL_DFU_ATXMEGA64A1U 0x2FE8
#define USB_PID_ATMEL_DFU_ATUC3D 0x2FE9
#define USB_PID_ATMEL_DFU_ATXMEGA128B1 0x2FEA
#define USB_PID_ATMEL_DFU_AT32UC3C 0x2FEB
#define USB_PID_ATMEL_DFU_ATXMEGA256A3U 0x2FEC
#define USB_PID_ATMEL_DFU_ATXMEGA128A1U 0x2FED
#define USB_PID_ATMEL_DFU_ATMEGA8U2 0x2FEE
#define USB_PID_ATMEL_DFU_ATMEGA16U2 0x2FEF
#define USB_PID_ATMEL_DFU_ATMEGA32U2 0x2FF0
#define USB_PID_ATMEL_DFU_AT32UC3A3 0x2FF1
#define USB_PID_ATMEL_DFU_ATMEGA32U6 0x2FF2
#define USB_PID_ATMEL_DFU_ATMEGA16U4 0x2FF3
#define USB_PID_ATMEL_DFU_ATMEGA32U4 0x2FF4
#define USB_PID_ATMEL_DFU_AT32AP7200 0x2FF5
#define USB_PID_ATMEL_DFU_AT32UC3B 0x2FF6
#define USB_PID_ATMEL_DFU_AT90USB82 0x2FF7
#define USB_PID_ATMEL_DFU_AT32UC3A 0x2FF8
#define USB_PID_ATMEL_DFU_AT90USB64 0x2FF9
#define USB_PID_ATMEL_DFU_AT90USB162 0x2FFA
#define USB_PID_ATMEL_DFU_AT90USB128 0x2FFB
// 2FFCh to 2FFFh used by C51 family products
//! @}
@ -186,5 +186,4 @@
//! @}
#endif // _USB_ATMEL_H_
#endif // _USB_ATMEL_H_

View file

@ -61,30 +61,30 @@
*/
// Check USB device configuration
#ifdef USB_DEVICE_HS_SUPPORT
# error The High speed mode is not supported on this part, please remove USB_DEVICE_HS_SUPPORT in conf_usb.h
# error The High speed mode is not supported on this part, please remove USB_DEVICE_HS_SUPPORT in conf_usb.h
#endif
//Note: This driver is adapted for SAMD51
// Note: This driver is adapted for SAMD51
#ifndef UDC_REMOTEWAKEUP_LPM_ENABLE
#define UDC_REMOTEWAKEUP_LPM_ENABLE()
# define UDC_REMOTEWAKEUP_LPM_ENABLE()
#endif
#ifndef UDC_REMOTEWAKEUP_LPM_DISABLE
#define UDC_REMOTEWAKEUP_LPM_DISABLE()
# define UDC_REMOTEWAKEUP_LPM_DISABLE()
#endif
#ifndef UDC_SUSPEND_LPM_EVENT
#define UDC_SUSPEND_LPM_EVENT()
# define UDC_SUSPEND_LPM_EVENT()
#endif
/* for debug text */
#ifdef USB_DEBUG
# define dbg_print printf
# define dbg_print printf
#else
# define dbg_print(...)
# define dbg_print(...)
#endif
/** Maximum size of a transfer in multi-packet mode */
#define UDD_ENDPOINT_MAX_TRANS ((8*1024)-1)
#define UDD_ENDPOINT_MAX_TRANS ((8 * 1024) - 1)
/** USB software device instance structure */
struct usb_module usb_device;
@ -97,10 +97,7 @@ struct usb_module usb_device;
#define UDD_CLOCK_GEN 0
static inline void udd_wait_clock_ready(void)
{
}
static inline void udd_wait_clock_ready(void) {}
/**
* \name Power management
@ -130,12 +127,12 @@ uint8_t udd_ctrl_buffer[USB_DEVICE_EP_CTRL_SIZE];
/** Bit definitions about endpoint control state machine for udd_ep_control_state */
typedef enum {
UDD_EPCTRL_SETUP = 0, //!< Wait a SETUP packet
UDD_EPCTRL_DATA_OUT = 1, //!< Wait a OUT data packet
UDD_EPCTRL_DATA_IN = 2, //!< Wait a IN data packet
UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP = 3, //!< Wait a IN ZLP packet
UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP = 4, //!< Wait a OUT ZLP packet
UDD_EPCTRL_STALL_REQ = 5, //!< STALL enabled on IN & OUT packet
UDD_EPCTRL_SETUP = 0, //!< Wait a SETUP packet
UDD_EPCTRL_DATA_OUT = 1, //!< Wait a OUT data packet
UDD_EPCTRL_DATA_IN = 2, //!< Wait a IN data packet
UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP = 3, //!< Wait a IN ZLP packet
UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP = 4, //!< Wait a OUT ZLP packet
UDD_EPCTRL_STALL_REQ = 5, //!< STALL enabled on IN & OUT packet
} udd_ctrl_ep_state_t;
/** Global variable to give and record information of the set up request management */
@ -200,11 +197,11 @@ typedef struct {
//! Endpoint size
uint16_t ep_size;
//! A job is registered on this endpoint
uint8_t busy:1;
uint8_t busy : 1;
//! A short packet is requested for this job on endpoint IN
uint8_t b_shortpacket:1;
uint8_t b_shortpacket : 1;
//! The cache buffer is currently used on endpoint OUT
uint8_t b_use_out_cache_buffer:1;
uint8_t b_use_out_cache_buffer : 1;
} udd_ep_job_t;
/** Array to register a job on bulk/interrupt/isochronous endpoint */
@ -217,8 +214,7 @@ static udd_ep_job_t udd_ep_job[2 * USB_DEVICE_MAX_EP];
* \param[in] ep Endpoint Address
* \retval pointer to an udd_ep_job_t structure instance
*/
static udd_ep_job_t* udd_ep_get_job(udd_ep_id_t ep)
{
static udd_ep_job_t *udd_ep_get_job(udd_ep_id_t ep) {
if ((ep == 0) || (ep == 0x80)) {
return NULL;
} else {
@ -230,17 +226,16 @@ static udd_ep_job_t* udd_ep_get_job(udd_ep_id_t ep)
* \brief Endpoint IN process, continue to send packets or zero length packet
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void udd_ep_trans_in_next(void* pointer)
{
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
udd_ep_id_t ep = ep_callback_para->endpoint_address;
uint16_t ep_size, nb_trans;
uint16_t next_trans;
udd_ep_id_t ep_num;
udd_ep_job_t *ptr_job;
static void udd_ep_trans_in_next(void *pointer) {
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
udd_ep_id_t ep = ep_callback_para->endpoint_address;
uint16_t ep_size, nb_trans;
uint16_t next_trans;
udd_ep_id_t ep_num;
udd_ep_job_t * ptr_job;
ptr_job = udd_ep_get_job(ep);
ep_num = ep & USB_EP_ADDR_MASK;
ep_num = ep & USB_EP_ADDR_MASK;
ep_size = ptr_job->ep_size;
/* Update number of data transferred */
@ -251,13 +246,13 @@ static void udd_ep_trans_in_next(void* pointer)
if (ptr_job->nb_trans != ptr_job->buf_size) {
next_trans = ptr_job->buf_size - ptr_job->nb_trans;
if (UDD_ENDPOINT_MAX_TRANS < next_trans) {
/* The USB hardware support a maximum
* transfer size of UDD_ENDPOINT_MAX_TRANS Bytes */
next_trans = UDD_ENDPOINT_MAX_TRANS -(UDD_ENDPOINT_MAX_TRANS % ep_size);
/* The USB hardware support a maximum
* transfer size of UDD_ENDPOINT_MAX_TRANS Bytes */
next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ep_size);
}
/* Need ZLP, if requested and last packet is not a short packet */
ptr_job->b_shortpacket = ptr_job->b_shortpacket && (0 == (next_trans % ep_size));
usb_device_endpoint_write_buffer_job(&usb_device,ep_num,&ptr_job->buf[ptr_job->nb_trans],next_trans);
usb_device_endpoint_write_buffer_job(&usb_device, ep_num, &ptr_job->buf[ptr_job->nb_trans], next_trans);
return;
}
@ -265,7 +260,7 @@ static void udd_ep_trans_in_next(void* pointer)
if (ptr_job->b_shortpacket) {
ptr_job->b_shortpacket = false;
/* Start new transfer */
usb_device_endpoint_write_buffer_job(&usb_device,ep_num,&ptr_job->buf[ptr_job->nb_trans],0);
usb_device_endpoint_write_buffer_job(&usb_device, ep_num, &ptr_job->buf[ptr_job->nb_trans], 0);
return;
}
@ -280,17 +275,16 @@ static void udd_ep_trans_in_next(void* pointer)
* \brief Endpoint OUT process, continue to receive packets or zero length packet
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void udd_ep_trans_out_next(void* pointer)
{
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
udd_ep_id_t ep = ep_callback_para->endpoint_address;
uint16_t ep_size, nb_trans;
uint16_t next_trans;
udd_ep_id_t ep_num;
udd_ep_job_t *ptr_job;
static void udd_ep_trans_out_next(void *pointer) {
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
udd_ep_id_t ep = ep_callback_para->endpoint_address;
uint16_t ep_size, nb_trans;
uint16_t next_trans;
udd_ep_id_t ep_num;
udd_ep_job_t * ptr_job;
ptr_job = udd_ep_get_job(ep);
ep_num = ep & USB_EP_ADDR_MASK;
ep_num = ep & USB_EP_ADDR_MASK;
ep_size = ptr_job->ep_size;
/* Update number of data transferred */
@ -312,9 +306,9 @@ static void udd_ep_trans_out_next(void* pointer)
if ((nb_trans == ep_callback_para->out_buffer_size) && (ptr_job->nb_trans != ptr_job->buf_size)) {
next_trans = ptr_job->buf_size - ptr_job->nb_trans;
if (UDD_ENDPOINT_MAX_TRANS < next_trans) {
/* The USB hardware support a maximum transfer size
* of UDD_ENDPOINT_MAX_TRANS Bytes */
next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ep_size);
/* The USB hardware support a maximum transfer size
* of UDD_ENDPOINT_MAX_TRANS Bytes */
next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ep_size);
} else {
next_trans -= next_trans % ep_size;
}
@ -322,9 +316,9 @@ static void udd_ep_trans_out_next(void* pointer)
if (next_trans < ep_size) {
/* Use the cache buffer for Bulk or Interrupt size endpoint */
ptr_job->b_use_out_cache_buffer = true;
usb_device_endpoint_read_buffer_job(&usb_device,ep_num,udd_ep_out_cache_buffer[ep_num - 1],ep_size);
usb_device_endpoint_read_buffer_job(&usb_device, ep_num, udd_ep_out_cache_buffer[ep_num - 1], ep_size);
} else {
usb_device_endpoint_read_buffer_job(&usb_device,ep_num,&ptr_job->buf[ptr_job->nb_trans],next_trans);
usb_device_endpoint_read_buffer_job(&usb_device, ep_num, &ptr_job->buf[ptr_job->nb_trans], next_trans);
}
return;
}
@ -341,10 +335,9 @@ static void udd_ep_trans_out_next(void* pointer)
* \param[in] module_inst Pointer to USB module instance
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void udd_ep_transfer_process(struct usb_module *module_inst, void* pointer)
{
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
udd_ep_id_t ep = ep_callback_para->endpoint_address;
static void udd_ep_transfer_process(struct usb_module *module_inst, void *pointer) {
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
udd_ep_id_t ep = ep_callback_para->endpoint_address;
if (ep & USB_EP_DIR_IN) {
udd_ep_trans_in_next(pointer);
@ -353,8 +346,7 @@ static void udd_ep_transfer_process(struct usb_module *module_inst, void* pointe
}
}
void udd_ep_abort(udd_ep_id_t ep)
{
void udd_ep_abort(udd_ep_id_t ep) {
udd_ep_job_t *ptr_job;
usb_device_endpoint_abort_job(&usb_device, ep);
@ -371,23 +363,13 @@ void udd_ep_abort(udd_ep_id_t ep)
}
}
bool udd_is_high_speed(void)
{
return false;
}
bool udd_is_high_speed(void) { return false; }
uint16_t udd_get_frame_number(void)
{
return usb_device_get_frame_number(&usb_device);
}
uint16_t udd_get_frame_number(void) { return usb_device_get_frame_number(&usb_device); }
uint16_t udd_get_micro_frame_number(void)
{
return usb_device_get_micro_frame_number(&usb_device);
}
uint16_t udd_get_micro_frame_number(void) { return usb_device_get_micro_frame_number(&usb_device); }
void udd_ep_free(udd_ep_id_t ep)
{
void udd_ep_free(udd_ep_id_t ep) {
struct usb_device_endpoint_config config_ep;
usb_device_endpoint_get_config_defaults(&config_ep);
@ -395,45 +377,44 @@ void udd_ep_free(udd_ep_id_t ep)
udd_ep_abort(ep);
config_ep.ep_address = ep;
config_ep.ep_type = USB_DEVICE_ENDPOINT_TYPE_DISABLE;
config_ep.ep_type = USB_DEVICE_ENDPOINT_TYPE_DISABLE;
usb_device_endpoint_set_config(&usb_device, &config_ep);
usb_device_endpoint_unregister_callback(&usb_device,ep_num,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
usb_device_endpoint_disable_callback(&usb_device,ep,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
usb_device_endpoint_unregister_callback(&usb_device, ep_num, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
usb_device_endpoint_disable_callback(&usb_device, ep, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
}
bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize)
{
bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize) {
struct usb_device_endpoint_config config_ep;
usb_device_endpoint_get_config_defaults(&config_ep);
config_ep.ep_address = ep;
if(MaxEndpointSize <= 8) {
if (MaxEndpointSize <= 8) {
config_ep.ep_size = USB_ENDPOINT_8_BYTE;
} else if(MaxEndpointSize <= 16) {
} else if (MaxEndpointSize <= 16) {
config_ep.ep_size = USB_ENDPOINT_16_BYTE;
} else if(MaxEndpointSize <= 32) {
} else if (MaxEndpointSize <= 32) {
config_ep.ep_size = USB_ENDPOINT_32_BYTE;
} else if(MaxEndpointSize <= 64) {
} else if (MaxEndpointSize <= 64) {
config_ep.ep_size = USB_ENDPOINT_64_BYTE;
} else if(MaxEndpointSize <= 128) {
} else if (MaxEndpointSize <= 128) {
config_ep.ep_size = USB_ENDPOINT_128_BYTE;
} else if(MaxEndpointSize <= 256) {
} else if (MaxEndpointSize <= 256) {
config_ep.ep_size = USB_ENDPOINT_256_BYTE;
} else if(MaxEndpointSize <= 512) {
} else if (MaxEndpointSize <= 512) {
config_ep.ep_size = USB_ENDPOINT_512_BYTE;
} else if(MaxEndpointSize <= 1023) {
} else if (MaxEndpointSize <= 1023) {
config_ep.ep_size = USB_ENDPOINT_1023_BYTE;
} else {
return false;
}
udd_ep_job_t *ptr_job = udd_ep_get_job(ep);
ptr_job->ep_size = MaxEndpointSize;
ptr_job->ep_size = MaxEndpointSize;
bmAttributes = bmAttributes & USB_EP_TYPE_MASK;
/* Check endpoint type */
if(USB_EP_TYPE_ISOCHRONOUS == bmAttributes) {
if (USB_EP_TYPE_ISOCHRONOUS == bmAttributes) {
config_ep.ep_type = USB_DEVICE_ENDPOINT_TYPE_ISOCHRONOUS;
} else if (USB_EP_TYPE_BULK == bmAttributes) {
config_ep.ep_type = USB_DEVICE_ENDPOINT_TYPE_BULK;
@ -448,20 +429,16 @@ bool udd_ep_alloc(udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize
if (STATUS_OK != usb_device_endpoint_set_config(&usb_device, &config_ep)) {
return false;
}
usb_device_endpoint_register_callback(&usb_device,ep_num,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT,udd_ep_transfer_process);
usb_device_endpoint_enable_callback(&usb_device,ep,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
usb_device_endpoint_enable_callback(&usb_device,ep,USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL);
usb_device_endpoint_register_callback(&usb_device, ep_num, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT, udd_ep_transfer_process);
usb_device_endpoint_enable_callback(&usb_device, ep, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
usb_device_endpoint_enable_callback(&usb_device, ep, USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL);
return true;
}
bool udd_ep_is_halted(udd_ep_id_t ep)
{
return usb_device_endpoint_is_halted(&usb_device, ep);
}
bool udd_ep_is_halted(udd_ep_id_t ep) { return usb_device_endpoint_is_halted(&usb_device, ep); }
bool udd_ep_set_halt(udd_ep_id_t ep)
{
bool udd_ep_set_halt(udd_ep_id_t ep) {
uint8_t ep_num = ep & USB_EP_ADDR_MASK;
if (USB_DEVICE_MAX_EP < ep_num) {
@ -474,10 +451,9 @@ bool udd_ep_set_halt(udd_ep_id_t ep)
return true;
}
bool udd_ep_clear_halt(udd_ep_id_t ep)
{
bool udd_ep_clear_halt(udd_ep_id_t ep) {
udd_ep_job_t *ptr_job;
uint8_t ep_num = ep & USB_EP_ADDR_MASK;
uint8_t ep_num = ep & USB_EP_ADDR_MASK;
if (USB_DEVICE_MAX_EP < ep_num) {
return false;
@ -495,9 +471,8 @@ bool udd_ep_clear_halt(udd_ep_id_t ep)
return true;
}
bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callback)
{
udd_ep_id_t ep_num;
bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callback) {
udd_ep_id_t ep_num;
udd_ep_job_t *ptr_job;
ep_num = ep & USB_EP_ADDR_MASK;
@ -513,7 +488,7 @@ bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callbac
/* Wait clear halt endpoint */
if (usb_device_endpoint_is_halted(&usb_device, ep)) {
/* Endpoint halted then registers the callback */
ptr_job->busy = true;
ptr_job->busy = true;
ptr_job->call_nohalt = callback;
return true;
} else if (usb_device_endpoint_is_configured(&usb_device, ep)) {
@ -527,19 +502,17 @@ bool udd_ep_wait_stall_clear(udd_ep_id_t ep, udd_callback_halt_cleared_t callbac
/**
* \brief Control Endpoint stall sending data
*/
static void udd_ctrl_stall_data(void)
{
static void udd_ctrl_stall_data(void) {
udd_ep_control_state = UDD_EPCTRL_STALL_REQ;
usb_device_endpoint_set_halt(&usb_device, USB_EP_DIR_IN);
usb_device_endpoint_clear_halt(&usb_device, USB_EP_DIR_OUT);
}
bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback)
{
udd_ep_id_t ep_num;
bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback) {
udd_ep_id_t ep_num;
udd_ep_job_t *ptr_job;
uint32_t irqflags;
uint32_t irqflags;
ep_num = ep & USB_EP_ADDR_MASK;
@ -564,11 +537,11 @@ bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t bu
__set_PRIMASK(irqflags);
/* No job running, set up a new one */
ptr_job->buf = buf;
ptr_job->buf_size = buf_size;
ptr_job->nb_trans = 0;
ptr_job->call_trans = callback;
ptr_job->b_shortpacket = b_shortpacket;
ptr_job->buf = buf;
ptr_job->buf_size = buf_size;
ptr_job->nb_trans = 0;
ptr_job->call_trans = callback;
ptr_job->b_shortpacket = b_shortpacket;
ptr_job->b_use_out_cache_buffer = false;
/* Initialize value to simulate a empty transfer */
@ -580,10 +553,10 @@ bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t bu
if (UDD_ENDPOINT_MAX_TRANS < next_trans) {
next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ptr_job->ep_size);
}
ptr_job->b_shortpacket = ptr_job->b_shortpacket && (0 == (next_trans % ptr_job->ep_size));
ptr_job->b_shortpacket = ptr_job->b_shortpacket && (0 == (next_trans % ptr_job->ep_size));
} else if (true == ptr_job->b_shortpacket) {
ptr_job->b_shortpacket = false; /* avoid to send zero length packet again */
next_trans = 0;
next_trans = 0;
} else {
ptr_job->busy = false;
if (NULL != ptr_job->call_trans) {
@ -591,30 +564,22 @@ bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t bu
}
return true;
}
return (STATUS_OK ==
usb_device_endpoint_write_buffer_job(&usb_device,
ep_num,&ptr_job->buf[0],next_trans));
return (STATUS_OK == usb_device_endpoint_write_buffer_job(&usb_device, ep_num, &ptr_job->buf[0], next_trans));
} else {
if (0 != ptr_job->buf_size) {
next_trans = ptr_job->buf_size;
if (UDD_ENDPOINT_MAX_TRANS < next_trans) {
/* The USB hardware support a maximum transfer size
* of UDD_ENDPOINT_MAX_TRANS Bytes */
next_trans = UDD_ENDPOINT_MAX_TRANS -
(UDD_ENDPOINT_MAX_TRANS % ptr_job->ep_size);
next_trans = UDD_ENDPOINT_MAX_TRANS - (UDD_ENDPOINT_MAX_TRANS % ptr_job->ep_size);
} else {
next_trans -= next_trans % ptr_job->ep_size;
}
if (next_trans < ptr_job->ep_size) {
ptr_job->b_use_out_cache_buffer = true;
return (STATUS_OK ==
usb_device_endpoint_read_buffer_job(&usb_device, ep_num,
udd_ep_out_cache_buffer[ep_num - 1],
ptr_job->ep_size));
return (STATUS_OK == usb_device_endpoint_read_buffer_job(&usb_device, ep_num, udd_ep_out_cache_buffer[ep_num - 1], ptr_job->ep_size));
} else {
return (STATUS_OK ==
usb_device_endpoint_read_buffer_job(&usb_device, ep_num,
&ptr_job->buf[0],next_trans));
return (STATUS_OK == usb_device_endpoint_read_buffer_job(&usb_device, ep_num, &ptr_job->buf[0], next_trans));
}
} else {
ptr_job->busy = false;
@ -626,61 +591,51 @@ bool udd_ep_run(udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t bu
}
}
void udd_set_address(uint8_t address)
{
usb_device_set_address(&usb_device,address);
}
void udd_set_address(uint8_t address) { usb_device_set_address(&usb_device, address); }
uint8_t udd_getaddress(void)
{
return usb_device_get_address(&usb_device);
}
uint8_t udd_getaddress(void) { return usb_device_get_address(&usb_device); }
void udd_send_remotewakeup(void)
{
uint32_t try = 5;
void udd_send_remotewakeup(void) {
uint32_t try
= 5;
udd_wait_clock_ready();
udd_sleep_mode(UDD_STATE_IDLE);
while(2 != usb_get_state_machine_status(&usb_device) && try --) {
while (2 != usb_get_state_machine_status(&usb_device) && try --) {
usb_device_send_remote_wake_up(&usb_device);
}
}
void udd_set_setup_payload( uint8_t *payload, uint16_t payload_size )
{
udd_g_ctrlreq.payload = payload;
void udd_set_setup_payload(uint8_t *payload, uint16_t payload_size) {
udd_g_ctrlreq.payload = payload;
udd_g_ctrlreq.payload_size = payload_size;
}
/**
* \brief Control Endpoint translate the data in buffer into Device Request Struct
*/
static void udd_ctrl_fetch_ram(void)
{
static void udd_ctrl_fetch_ram(void) {
udd_g_ctrlreq.req.bmRequestType = udd_ctrl_buffer[0];
udd_g_ctrlreq.req.bRequest = udd_ctrl_buffer[1];
udd_g_ctrlreq.req.wValue = ((uint16_t)(udd_ctrl_buffer[3]) << 8) + udd_ctrl_buffer[2];
udd_g_ctrlreq.req.wIndex = ((uint16_t)(udd_ctrl_buffer[5]) << 8) + udd_ctrl_buffer[4];
udd_g_ctrlreq.req.wLength = ((uint16_t)(udd_ctrl_buffer[7]) << 8) + udd_ctrl_buffer[6];
udd_g_ctrlreq.req.bRequest = udd_ctrl_buffer[1];
udd_g_ctrlreq.req.wValue = ((uint16_t)(udd_ctrl_buffer[3]) << 8) + udd_ctrl_buffer[2];
udd_g_ctrlreq.req.wIndex = ((uint16_t)(udd_ctrl_buffer[5]) << 8) + udd_ctrl_buffer[4];
udd_g_ctrlreq.req.wLength = ((uint16_t)(udd_ctrl_buffer[7]) << 8) + udd_ctrl_buffer[6];
}
/**
* \brief Control Endpoint send out zero length packet
*/
static void udd_ctrl_send_zlp_in(void)
{
static void udd_ctrl_send_zlp_in(void) {
udd_ep_control_state = UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP;
usb_device_endpoint_setup_buffer_job(&usb_device,udd_ctrl_buffer);
usb_device_endpoint_write_buffer_job(&usb_device,0,udd_g_ctrlreq.payload,0);
usb_device_endpoint_setup_buffer_job(&usb_device, udd_ctrl_buffer);
usb_device_endpoint_write_buffer_job(&usb_device, 0, udd_g_ctrlreq.payload, 0);
}
/**
* \brief Process control endpoint IN transaction
*/
static void udd_ctrl_in_sent(void)
{
static void udd_ctrl_in_sent(void) {
static bool b_shortpacket = false;
uint16_t nb_remain;
uint16_t nb_remain;
nb_remain = udd_g_ctrlreq.payload_size - udd_ctrl_payload_nb_trans;
@ -691,7 +646,7 @@ static void udd_ctrl_in_sent(void)
/* All data requested are transferred or a short packet has been sent, then it is the end of data phase.
* Generate an OUT ZLP for handshake phase */
udd_ep_control_state = UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP;
usb_device_endpoint_setup_buffer_job(&usb_device,udd_ctrl_buffer);
usb_device_endpoint_setup_buffer_job(&usb_device, udd_ctrl_buffer);
return;
}
/* Need of new buffer because the data phase is not complete */
@ -701,20 +656,20 @@ static void udd_ctrl_in_sent(void)
} else {
/* A new payload buffer is given */
udd_ctrl_payload_nb_trans = 0;
nb_remain = udd_g_ctrlreq.payload_size;
nb_remain = udd_g_ctrlreq.payload_size;
}
}
/* Continue transfer and send next data */
if (nb_remain >= USB_DEVICE_EP_CTRL_SIZE) {
nb_remain = USB_DEVICE_EP_CTRL_SIZE;
nb_remain = USB_DEVICE_EP_CTRL_SIZE;
b_shortpacket = false;
} else {
b_shortpacket = true;
}
/* Link payload buffer directly on USB hardware */
usb_device_endpoint_write_buffer_job(&usb_device,0,udd_g_ctrlreq.payload + udd_ctrl_payload_nb_trans,nb_remain);
usb_device_endpoint_write_buffer_job(&usb_device, 0, udd_g_ctrlreq.payload + udd_ctrl_payload_nb_trans, nb_remain);
udd_ctrl_payload_nb_trans += nb_remain;
}
@ -723,9 +678,8 @@ static void udd_ctrl_in_sent(void)
* \brief Process control endpoint OUT transaction
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void udd_ctrl_out_received(void* pointer)
{
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
static void udd_ctrl_out_received(void *pointer) {
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
uint16_t nb_data;
nb_data = ep_callback_para->received_bytes; /* Read data received during OUT phase */
@ -735,11 +689,10 @@ static void udd_ctrl_out_received(void* pointer)
nb_data = udd_g_ctrlreq.payload_size - udd_ctrl_payload_nb_trans;
}
memcpy((uint8_t *) (udd_g_ctrlreq.payload + udd_ctrl_payload_nb_trans), udd_ctrl_buffer, nb_data);
memcpy((uint8_t *)(udd_g_ctrlreq.payload + udd_ctrl_payload_nb_trans), udd_ctrl_buffer, nb_data);
udd_ctrl_payload_nb_trans += nb_data;
if ((USB_DEVICE_EP_CTRL_SIZE != nb_data) || \
(udd_g_ctrlreq.req.wLength <= (udd_ctrl_prev_payload_nb_trans + udd_ctrl_payload_nb_trans))) {
if ((USB_DEVICE_EP_CTRL_SIZE != nb_data) || (udd_g_ctrlreq.req.wLength <= (udd_ctrl_prev_payload_nb_trans + udd_ctrl_payload_nb_trans))) {
/* End of reception because it is a short packet
* or all data are transferred */
@ -786,7 +739,7 @@ static void udd_ctrl_out_received(void* pointer)
/* Reinitialize reception on payload buffer */
udd_ctrl_payload_nb_trans = 0;
}
usb_device_endpoint_read_buffer_job(&usb_device,0,udd_ctrl_buffer,USB_DEVICE_EP_CTRL_SIZE);
usb_device_endpoint_read_buffer_job(&usb_device, 0, udd_ctrl_buffer, USB_DEVICE_EP_CTRL_SIZE);
}
/**
@ -795,9 +748,8 @@ static void udd_ctrl_out_received(void* pointer)
* \param[in] module_inst pointer to USB module instance
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void _usb_ep0_on_setup(struct usb_module *module_inst, void* pointer)
{
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
static void _usb_ep0_on_setup(struct usb_module *module_inst, void *pointer) {
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
if (UDD_EPCTRL_SETUP != udd_ep_control_state) {
if (NULL != udd_g_ctrlreq.callback) {
@ -805,7 +757,7 @@ static void _usb_ep0_on_setup(struct usb_module *module_inst, void* pointer)
}
udd_ep_control_state = UDD_EPCTRL_SETUP;
}
if ( 8 != ep_callback_para->received_bytes) {
if (8 != ep_callback_para->received_bytes) {
udd_ctrl_stall_data();
return;
} else {
@ -815,20 +767,20 @@ static void _usb_ep0_on_setup(struct usb_module *module_inst, void* pointer)
return;
} else if (Udd_setup_is_in()) {
udd_ctrl_prev_payload_nb_trans = 0;
udd_ctrl_payload_nb_trans = 0;
udd_ep_control_state = UDD_EPCTRL_DATA_IN;
usb_device_endpoint_read_buffer_job(&usb_device,0,udd_ctrl_buffer,USB_DEVICE_EP_CTRL_SIZE);
udd_ctrl_payload_nb_trans = 0;
udd_ep_control_state = UDD_EPCTRL_DATA_IN;
usb_device_endpoint_read_buffer_job(&usb_device, 0, udd_ctrl_buffer, USB_DEVICE_EP_CTRL_SIZE);
udd_ctrl_in_sent();
} else {
if(0 == udd_g_ctrlreq.req.wLength) {
if (0 == udd_g_ctrlreq.req.wLength) {
udd_ctrl_send_zlp_in();
return;
} else {
udd_ctrl_prev_payload_nb_trans = 0;
udd_ctrl_payload_nb_trans = 0;
udd_ep_control_state = UDD_EPCTRL_DATA_OUT;
udd_ctrl_payload_nb_trans = 0;
udd_ep_control_state = UDD_EPCTRL_DATA_OUT;
/* Initialize buffer size and enable OUT bank */
usb_device_endpoint_read_buffer_job(&usb_device,0,udd_ctrl_buffer,USB_DEVICE_EP_CTRL_SIZE);
usb_device_endpoint_read_buffer_job(&usb_device, 0, udd_ctrl_buffer, USB_DEVICE_EP_CTRL_SIZE);
}
}
}
@ -838,9 +790,8 @@ static void _usb_ep0_on_setup(struct usb_module *module_inst, void* pointer)
* \brief Control Endpoint Process when underflow condition has occurred
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void udd_ctrl_underflow(void* pointer)
{
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
static void udd_ctrl_underflow(void *pointer) {
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
if (UDD_EPCTRL_DATA_OUT == udd_ep_control_state) {
/* Host want to stop OUT transaction
@ -857,9 +808,8 @@ static void udd_ctrl_underflow(void* pointer)
* \brief Control Endpoint Process when overflow condition has occurred
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void udd_ctrl_overflow(void* pointer)
{
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
static void udd_ctrl_overflow(void *pointer) {
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
if (UDD_EPCTRL_DATA_IN == udd_ep_control_state) {
/* Host want to stop IN transaction
@ -878,11 +828,10 @@ static void udd_ctrl_overflow(void* pointer)
* \param[in] module_inst Pointer to USB module instance
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void _usb_ep0_on_tansfer_fail(struct usb_module *module_inst, void* pointer)
{
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter*)pointer;
static void _usb_ep0_on_tansfer_fail(struct usb_module *module_inst, void *pointer) {
struct usb_endpoint_callback_parameter *ep_callback_para = (struct usb_endpoint_callback_parameter *)pointer;
if(ep_callback_para->endpoint_address & USB_EP_DIR_IN) {
if (ep_callback_para->endpoint_address & USB_EP_DIR_IN) {
udd_ctrl_underflow(pointer);
} else {
udd_ctrl_overflow(pointer);
@ -895,9 +844,8 @@ static void _usb_ep0_on_tansfer_fail(struct usb_module *module_inst, void* point
* \param[in] module_inst Pointer to USB module instance
* \param[in] pointer Pointer to the endpoint transfer status parameter struct from driver layer.
*/
static void _usb_ep0_on_tansfer_ok(struct usb_module *module_inst, void *pointer)
{
if (UDD_EPCTRL_DATA_OUT == udd_ep_control_state) { /* handshake Out for status stage */
static void _usb_ep0_on_tansfer_ok(struct usb_module *module_inst, void *pointer) {
if (UDD_EPCTRL_DATA_OUT == udd_ep_control_state) { /* handshake Out for status stage */
udd_ctrl_out_received(pointer);
} else if (UDD_EPCTRL_DATA_IN == udd_ep_control_state) { /* handshake In for status stage */
udd_ctrl_in_sent();
@ -913,25 +861,24 @@ static void _usb_ep0_on_tansfer_ok(struct usb_module *module_inst, void *pointer
* \brief Enable Control Endpoint
* \param[in] module_inst Pointer to USB module instance
*/
static void udd_ctrl_ep_enable(struct usb_module *module_inst)
{
static void udd_ctrl_ep_enable(struct usb_module *module_inst) {
/* USB Device Endpoint0 Configuration */
struct usb_device_endpoint_config config_ep0;
usb_device_endpoint_get_config_defaults(&config_ep0);
config_ep0.ep_size = (enum usb_endpoint_size)(32 - clz(((uint32_t)Min(Max(USB_DEVICE_EP_CTRL_SIZE, 8), 1024) << 1) - 1) - 1 - 3);
usb_device_endpoint_set_config(module_inst,&config_ep0);
usb_device_endpoint_set_config(module_inst, &config_ep0);
usb_device_endpoint_setup_buffer_job(module_inst,udd_ctrl_buffer);
usb_device_endpoint_setup_buffer_job(module_inst, udd_ctrl_buffer);
usb_device_endpoint_register_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_RXSTP, _usb_ep0_on_setup );
usb_device_endpoint_register_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT,_usb_ep0_on_tansfer_ok );
usb_device_endpoint_register_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL,_usb_ep0_on_tansfer_fail );
usb_device_endpoint_enable_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_RXSTP);
usb_device_endpoint_enable_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
usb_device_endpoint_enable_callback(module_inst,0,USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL);
usb_device_endpoint_register_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_RXSTP, _usb_ep0_on_setup);
usb_device_endpoint_register_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT, _usb_ep0_on_tansfer_ok);
usb_device_endpoint_register_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL, _usb_ep0_on_tansfer_fail);
usb_device_endpoint_enable_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_RXSTP);
usb_device_endpoint_enable_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT);
usb_device_endpoint_enable_callback(module_inst, 0, USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL);
#ifdef USB_DEVICE_LPM_SUPPORT
#ifdef USB_DEVICE_LPM_SUPPORT
// Enable LPM feature
usb_device_set_lpm_mode(module_inst, USB_DEVICE_LPM_ACK);
#endif
@ -945,8 +892,7 @@ static void udd_ctrl_ep_enable(struct usb_module *module_inst)
* \param[in] module_inst Pointer to USB module instance
* \param[in] pointer Pointer to the callback parameter from driver layer.
*/
static void _usb_on_suspend(struct usb_module *module_inst, void *pointer)
{
static void _usb_on_suspend(struct usb_module *module_inst, void *pointer) {
usb_device_disable_callback(&usb_device, USB_DEVICE_CALLBACK_SUSPEND);
usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_WAKEUP);
udd_sleep_mode(UDD_STATE_SUSPEND);
@ -955,9 +901,8 @@ static void _usb_on_suspend(struct usb_module *module_inst, void *pointer)
#endif
}
#ifdef USB_DEVICE_LPM_SUPPORT
static void _usb_device_lpm_suspend(struct usb_module *module_inst, void *pointer)
{
#ifdef USB_DEVICE_LPM_SUPPORT
static void _usb_device_lpm_suspend(struct usb_module *module_inst, void *pointer) {
dbg_print("LPM_SUSP\n");
uint32_t *lpm_wakeup_enable;
@ -967,7 +912,7 @@ static void _usb_device_lpm_suspend(struct usb_module *module_inst, void *pointe
usb_device_disable_callback(&usb_device, USB_DEVICE_CALLBACK_SUSPEND);
usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_WAKEUP);
//#warning Here the sleep mode must be choose to have a DFLL startup time < bmAttribut.HIRD
//#warning Here the sleep mode must be choose to have a DFLL startup time < bmAttribut.HIRD
udd_sleep_mode(UDD_STATE_SUSPEND_LPM); // Enter in LPM SUSPEND mode
if ((*lpm_wakeup_enable)) {
UDC_REMOTEWAKEUP_LPM_ENABLE();
@ -985,8 +930,7 @@ static void _usb_device_lpm_suspend(struct usb_module *module_inst, void *pointe
* \param[in] module_inst Pointer to USB module instance
* \param[in] pointer Pointer to the callback parameter from driver layer.
*/
static void _usb_on_sof_notify(struct usb_module *module_inst, void *pointer)
{
static void _usb_on_sof_notify(struct usb_module *module_inst, void *pointer) {
udc_sof_notify();
#ifdef UDC_SOF_EVENT
UDC_SOF_EVENT();
@ -999,11 +943,10 @@ static void _usb_on_sof_notify(struct usb_module *module_inst, void *pointer)
* \param[in] module_inst Pointer to USB module instance
* \param[in] pointer Pointer to the callback parameter from driver layer.
*/
static void _usb_on_bus_reset(struct usb_module *module_inst, void *pointer)
{
static void _usb_on_bus_reset(struct usb_module *module_inst, void *pointer) {
// Reset USB Device Stack Core
udc_reset();
usb_device_set_address(module_inst,0);
usb_device_set_address(module_inst, 0);
udd_ctrl_ep_enable(module_inst);
}
@ -1013,13 +956,12 @@ static void _usb_on_bus_reset(struct usb_module *module_inst, void *pointer)
* \param[in] module_inst Pointer to USB module instance
* \param[in] pointer Pointer to the callback parameter from driver layer.
*/
static void _usb_on_wakeup(struct usb_module *module_inst, void *pointer)
{
static void _usb_on_wakeup(struct usb_module *module_inst, void *pointer) {
udd_wait_clock_ready();
usb_device_disable_callback(&usb_device, USB_DEVICE_CALLBACK_WAKEUP);
usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_SUSPEND);
#ifdef USB_DEVICE_LPM_SUPPORT
#ifdef USB_DEVICE_LPM_SUPPORT
usb_device_register_callback(&usb_device, USB_DEVICE_CALLBACK_LPMSUSP, _usb_device_lpm_suspend);
usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_LPMSUSP);
#endif
@ -1029,14 +971,12 @@ static void _usb_on_wakeup(struct usb_module *module_inst, void *pointer)
#endif
}
void udd_detach(void)
{
void udd_detach(void) {
usb_device_detach(&usb_device);
udd_sleep_mode(UDD_STATE_SUSPEND);
}
void udd_attach(void)
{
void udd_attach(void) {
udd_sleep_mode(UDD_STATE_IDLE);
usb_device_attach(&usb_device);
@ -1049,14 +989,13 @@ void udd_attach(void)
usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_SOF);
usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_RESET);
usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_WAKEUP);
#ifdef USB_DEVICE_LPM_SUPPORT
#ifdef USB_DEVICE_LPM_SUPPORT
usb_device_register_callback(&usb_device, USB_DEVICE_CALLBACK_LPMSUSP, _usb_device_lpm_suspend);
usb_device_enable_callback(&usb_device, USB_DEVICE_CALLBACK_LPMSUSP);
#endif
}
void udd_enable(void)
{
void udd_enable(void) {
uint32_t irqflags;
/* To avoid USB interrupt before end of initialization */
@ -1088,8 +1027,7 @@ void udd_enable(void)
__set_PRIMASK(irqflags);
}
void udd_disable(void)
{
void udd_disable(void) {
udd_detach();
udd_sleep_mode(UDD_STATE_OFF);

View file

@ -47,57 +47,56 @@
#ifndef _MAIN_H_
#define _MAIN_H_
//Enters the application in low power mode
//Callback called when USB host sets USB line in suspend state
// Enters the application in low power mode
// Callback called when USB host sets USB line in suspend state
void main_suspend_action(void);
//Called by UDD when the USB line exit of suspend state
// Called by UDD when the USB line exit of suspend state
void main_resume_action(void);
//Called when a start of frame is received on USB line
// Called when a start of frame is received on USB line
void main_sof_action(void);
//Called by UDC when USB Host request to enable remote wakeup
// Called by UDC when USB Host request to enable remote wakeup
void main_remotewakeup_enable(void);
//Called by UDC when USB Host request to disable remote wakeup
// Called by UDC when USB Host request to disable remote wakeup
void main_remotewakeup_disable(void);
#ifdef KBD
extern volatile bool main_b_kbd_enable;
bool main_kbd_enable(void);
void main_kbd_disable(void);
#endif //KBD
bool main_kbd_enable(void);
void main_kbd_disable(void);
#endif // KBD
#ifdef NKRO
extern volatile bool main_b_nkro_enable;
bool main_nkro_enable(void);
void main_nkro_disable(void);
#endif //NKRO
bool main_nkro_enable(void);
void main_nkro_disable(void);
#endif // NKRO
#ifdef EXK
extern volatile bool main_b_exk_enable;
bool main_exk_enable(void);
void main_exk_disable(void);
#endif //EXK
bool main_exk_enable(void);
void main_exk_disable(void);
#endif // EXK
#ifdef CON
extern volatile bool main_b_con_enable;
bool main_con_enable(void);
void main_con_disable(void);
#endif //CON
bool main_con_enable(void);
void main_con_disable(void);
#endif // CON
#ifdef MOU
extern volatile bool main_b_mou_enable;
bool main_mou_enable(void);
void main_mou_disable(void);
#endif //MOU
bool main_mou_enable(void);
void main_mou_disable(void);
#endif // MOU
#ifdef RAW
extern volatile bool main_b_raw_enable;
bool main_raw_enable(void);
void main_raw_disable(void);
#endif //RAW
bool main_raw_enable(void);
void main_raw_disable(void);
#endif // RAW
#endif // _MAIN_H_
#endif // _MAIN_H_

View file

@ -63,83 +63,77 @@
*/
//! Value for field bcdUSB
#define USB_V2_0 0x0200 //!< USB Specification version 2.00
#define USB_V2_1 0x0201 //!< USB Specification version 2.01
#define USB_V2_0 0x0200 //!< USB Specification version 2.00
#define USB_V2_1 0x0201 //!< USB Specification version 2.01
/*! \name Generic definitions (Class, subclass and protocol)
*/
//! @{
#define NO_CLASS 0x00
#define CLASS_VENDOR_SPECIFIC 0xFF
#define NO_SUBCLASS 0x00
#define NO_PROTOCOL 0x00
#define NO_CLASS 0x00
#define CLASS_VENDOR_SPECIFIC 0xFF
#define NO_SUBCLASS 0x00
#define NO_PROTOCOL 0x00
//! @}
//! \name IAD (Interface Association Descriptor) constants
//! @{
#define CLASS_IAD 0xEF
#define SUB_CLASS_IAD 0x02
#define PROTOCOL_IAD 0x01
#define CLASS_IAD 0xEF
#define SUB_CLASS_IAD 0x02
#define PROTOCOL_IAD 0x01
//! @}
/**
* \brief USB request data transfer direction (bmRequestType)
*/
#define USB_REQ_DIR_OUT (0<<7) //!< Host to device
#define USB_REQ_DIR_IN (1<<7) //!< Device to host
#define USB_REQ_DIR_MASK (1<<7) //!< Mask
#define USB_REQ_DIR_OUT (0 << 7) //!< Host to device
#define USB_REQ_DIR_IN (1 << 7) //!< Device to host
#define USB_REQ_DIR_MASK (1 << 7) //!< Mask
/**
* \brief USB request types (bmRequestType)
*/
#define USB_REQ_TYPE_STANDARD (0<<5) //!< Standard request
#define USB_REQ_TYPE_CLASS (1<<5) //!< Class-specific request
#define USB_REQ_TYPE_VENDOR (2<<5) //!< Vendor-specific request
#define USB_REQ_TYPE_MASK (3<<5) //!< Mask
#define USB_REQ_TYPE_STANDARD (0 << 5) //!< Standard request
#define USB_REQ_TYPE_CLASS (1 << 5) //!< Class-specific request
#define USB_REQ_TYPE_VENDOR (2 << 5) //!< Vendor-specific request
#define USB_REQ_TYPE_MASK (3 << 5) //!< Mask
/**
* \brief USB recipient codes (bmRequestType)
*/
#define USB_REQ_RECIP_DEVICE (0<<0) //!< Recipient device
#define USB_REQ_RECIP_INTERFACE (1<<0) //!< Recipient interface
#define USB_REQ_RECIP_ENDPOINT (2<<0) //!< Recipient endpoint
#define USB_REQ_RECIP_OTHER (3<<0) //!< Recipient other
#define USB_REQ_RECIP_MASK (0x1F) //!< Mask
#define USB_REQ_RECIP_DEVICE (0 << 0) //!< Recipient device
#define USB_REQ_RECIP_INTERFACE (1 << 0) //!< Recipient interface
#define USB_REQ_RECIP_ENDPOINT (2 << 0) //!< Recipient endpoint
#define USB_REQ_RECIP_OTHER (3 << 0) //!< Recipient other
#define USB_REQ_RECIP_MASK (0x1F) //!< Mask
/**
* \brief Standard USB requests (bRequest)
*/
enum usb_reqid {
USB_REQ_GET_STATUS = 0,
USB_REQ_CLEAR_FEATURE = 1,
USB_REQ_SET_FEATURE = 3,
USB_REQ_SET_ADDRESS = 5,
USB_REQ_GET_DESCRIPTOR = 6,
USB_REQ_SET_DESCRIPTOR = 7,
USB_REQ_GET_STATUS = 0,
USB_REQ_CLEAR_FEATURE = 1,
USB_REQ_SET_FEATURE = 3,
USB_REQ_SET_ADDRESS = 5,
USB_REQ_GET_DESCRIPTOR = 6,
USB_REQ_SET_DESCRIPTOR = 7,
USB_REQ_GET_CONFIGURATION = 8,
USB_REQ_SET_CONFIGURATION = 9,
USB_REQ_GET_INTERFACE = 10,
USB_REQ_SET_INTERFACE = 11,
USB_REQ_SYNCH_FRAME = 12,
USB_REQ_GET_INTERFACE = 10,
USB_REQ_SET_INTERFACE = 11,
USB_REQ_SYNCH_FRAME = 12,
};
/**
* \brief Standard USB device status flags
*
*/
enum usb_device_status {
USB_DEV_STATUS_BUS_POWERED = 0,
USB_DEV_STATUS_SELF_POWERED = 1,
USB_DEV_STATUS_REMOTEWAKEUP = 2
};
enum usb_device_status { USB_DEV_STATUS_BUS_POWERED = 0, USB_DEV_STATUS_SELF_POWERED = 1, USB_DEV_STATUS_REMOTEWAKEUP = 2 };
/**
* \brief Standard USB Interface status flags
*
*/
enum usb_interface_status {
USB_IFACE_STATUS_RESERVED = 0
};
enum usb_interface_status { USB_IFACE_STATUS_RESERVED = 0 };
/**
* \brief Standard USB endpoint status flags
@ -155,10 +149,10 @@ enum usb_endpoint_status {
* \note valid for SetFeature request.
*/
enum usb_device_feature {
USB_DEV_FEATURE_REMOTE_WAKEUP = 1, //!< Remote wakeup enabled
USB_DEV_FEATURE_TEST_MODE = 2, //!< USB test mode
USB_DEV_FEATURE_OTG_B_HNP_ENABLE = 3,
USB_DEV_FEATURE_OTG_A_HNP_SUPPORT = 4,
USB_DEV_FEATURE_REMOTE_WAKEUP = 1, //!< Remote wakeup enabled
USB_DEV_FEATURE_TEST_MODE = 2, //!< USB test mode
USB_DEV_FEATURE_OTG_B_HNP_ENABLE = 3,
USB_DEV_FEATURE_OTG_A_HNP_SUPPORT = 4,
USB_DEV_FEATURE_OTG_A_ALT_HNP_SUPPORT = 5
};
@ -168,10 +162,10 @@ enum usb_device_feature {
* \note valid for USB_DEV_FEATURE_TEST_MODE request.
*/
enum usb_device_hs_test_mode {
USB_DEV_TEST_MODE_J = 1,
USB_DEV_TEST_MODE_K = 2,
USB_DEV_TEST_MODE_SE0_NAK = 3,
USB_DEV_TEST_MODE_PACKET = 4,
USB_DEV_TEST_MODE_J = 1,
USB_DEV_TEST_MODE_K = 2,
USB_DEV_TEST_MODE_SE0_NAK = 3,
USB_DEV_TEST_MODE_PACKET = 4,
USB_DEV_TEST_MODE_FORCE_ENABLE = 5,
};
@ -186,10 +180,10 @@ enum usb_endpoint_feature {
* \brief Standard USB Test Mode Selectors
*/
enum usb_test_mode_selector {
USB_TEST_J = 0x01,
USB_TEST_K = 0x02,
USB_TEST_SE0_NAK = 0x03,
USB_TEST_PACKET = 0x04,
USB_TEST_J = 0x01,
USB_TEST_K = 0x02,
USB_TEST_SE0_NAK = 0x03,
USB_TEST_PACKET = 0x04,
USB_TEST_FORCE_ENABLE = 0x05,
};
@ -197,18 +191,18 @@ enum usb_test_mode_selector {
* \brief Standard USB descriptor types
*/
enum usb_descriptor_type {
USB_DT_DEVICE = 1,
USB_DT_CONFIGURATION = 2,
USB_DT_STRING = 3,
USB_DT_INTERFACE = 4,
USB_DT_ENDPOINT = 5,
USB_DT_DEVICE_QUALIFIER = 6,
USB_DT_DEVICE = 1,
USB_DT_CONFIGURATION = 2,
USB_DT_STRING = 3,
USB_DT_INTERFACE = 4,
USB_DT_ENDPOINT = 5,
USB_DT_DEVICE_QUALIFIER = 6,
USB_DT_OTHER_SPEED_CONFIGURATION = 7,
USB_DT_INTERFACE_POWER = 8,
USB_DT_OTG = 9,
USB_DT_IAD = 0x0B,
USB_DT_BOS = 0x0F,
USB_DT_DEVICE_CAPABILITY = 0x10,
USB_DT_INTERFACE_POWER = 8,
USB_DT_OTG = 9,
USB_DT_IAD = 0x0B,
USB_DT_BOS = 0x0F,
USB_DT_DEVICE_CAPABILITY = 0x10,
};
/**
@ -223,57 +217,57 @@ enum usb_capability_type {
* To fill bmAttributes field of usb_capa_ext_desc_t structure.
*/
enum usb_capability_extension_attr {
USB_DC_EXT_LPM = 0x00000002,
USB_DC_EXT_LPM = 0x00000002,
};
#define HIRD_50_US 0
#define HIRD_125_US 1
#define HIRD_200_US 2
#define HIRD_275_US 3
#define HIRD_350_US 4
#define HIRD_425_US 5
#define HIRD_500_US 6
#define HIRD_575_US 7
#define HIRD_650_US 8
#define HIRD_725_US 9
#define HIRD_800_US 10
#define HIRD_875_US 11
#define HIRD_950_US 12
#define HIRD_1025_US 13
#define HIRD_1100_US 14
#define HIRD_1175_US 15
#define HIRD_50_US 0
#define HIRD_125_US 1
#define HIRD_200_US 2
#define HIRD_275_US 3
#define HIRD_350_US 4
#define HIRD_425_US 5
#define HIRD_500_US 6
#define HIRD_575_US 7
#define HIRD_650_US 8
#define HIRD_725_US 9
#define HIRD_800_US 10
#define HIRD_875_US 11
#define HIRD_950_US 12
#define HIRD_1025_US 13
#define HIRD_1100_US 14
#define HIRD_1175_US 15
/** Fields definition from a LPM TOKEN */
#define USB_LPM_ATTRIBUT_BLINKSTATE_MASK (0xF << 0)
#define USB_LPM_ATTRIBUT_FIRD_MASK (0xF << 4)
#define USB_LPM_ATTRIBUT_REMOTEWAKE_MASK (1 << 8)
#define USB_LPM_ATTRIBUT_BLINKSTATE(value) ((value & 0xF) << 0)
#define USB_LPM_ATTRIBUT_FIRD(value) ((value & 0xF) << 4)
#define USB_LPM_ATTRIBUT_REMOTEWAKE(value) ((value & 1) << 8)
#define USB_LPM_ATTRIBUT_BLINKSTATE_L1 USB_LPM_ATTRIBUT_BLINKSTATE(1)
#define USB_LPM_ATTRIBUT_BLINKSTATE_MASK (0xF << 0)
#define USB_LPM_ATTRIBUT_FIRD_MASK (0xF << 4)
#define USB_LPM_ATTRIBUT_REMOTEWAKE_MASK (1 << 8)
#define USB_LPM_ATTRIBUT_BLINKSTATE(value) ((value & 0xF) << 0)
#define USB_LPM_ATTRIBUT_FIRD(value) ((value & 0xF) << 4)
#define USB_LPM_ATTRIBUT_REMOTEWAKE(value) ((value & 1) << 8)
#define USB_LPM_ATTRIBUT_BLINKSTATE_L1 USB_LPM_ATTRIBUT_BLINKSTATE(1)
/**
* \brief Standard USB endpoint transfer types
*/
enum usb_ep_type {
USB_EP_TYPE_CONTROL = 0x00,
USB_EP_TYPE_CONTROL = 0x00,
USB_EP_TYPE_ISOCHRONOUS = 0x01,
USB_EP_TYPE_BULK = 0x02,
USB_EP_TYPE_INTERRUPT = 0x03,
USB_EP_TYPE_MASK = 0x03,
USB_EP_TYPE_BULK = 0x02,
USB_EP_TYPE_INTERRUPT = 0x03,
USB_EP_TYPE_MASK = 0x03,
};
/**
* \brief Standard USB language IDs for string descriptors
*/
enum usb_langid {
USB_LANGID_EN_US = 0x0409, //!< English (United States)
USB_LANGID_EN_US = 0x0409, //!< English (United States)
};
/**
* \brief Mask selecting the index part of an endpoint address
*/
#define USB_EP_ADDR_MASK 0x0f
#define USB_EP_ADDR_MASK 0x0f
//! \brief USB address identifier
typedef uint8_t usb_add_t;
@ -281,12 +275,12 @@ typedef uint8_t usb_add_t;
/**
* \brief Endpoint transfer direction is IN
*/
#define USB_EP_DIR_IN 0x80
#define USB_EP_DIR_IN 0x80
/**
* \brief Endpoint transfer direction is OUT
*/
#define USB_EP_DIR_OUT 0x00
#define USB_EP_DIR_OUT 0x00
//! \brief Endpoint identifier
typedef uint8_t usb_ep_t;
@ -297,7 +291,7 @@ typedef uint8_t usb_ep_t;
* The maximum length of a USB descriptor is limited by the 8-bit
* bLength field.
*/
#define USB_MAX_DESC_LEN 255
#define USB_MAX_DESC_LEN 255
/*
* 2-byte alignment requested for all USB structures.
@ -312,9 +306,9 @@ COMPILER_PACK_SET(1)
typedef struct {
uint8_t bmRequestType;
uint8_t bRequest;
le16_t wValue;
le16_t wIndex;
le16_t wLength;
le16_t wValue;
le16_t wIndex;
le16_t wLength;
} usb_setup_req_t;
/**
@ -323,14 +317,14 @@ typedef struct {
typedef struct {
uint8_t bLength;
uint8_t bDescriptorType;
le16_t bcdUSB;
le16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
le16_t idVendor;
le16_t idProduct;
le16_t bcdDevice;
le16_t idVendor;
le16_t idProduct;
le16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
@ -348,7 +342,7 @@ typedef struct {
typedef struct {
uint8_t bLength;
uint8_t bDescriptorType;
le16_t bcdUSB;
le16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
@ -376,7 +370,6 @@ typedef struct {
uint8_t bNumDeviceCaps;
} usb_dev_bos_desc_t;
/**
* \brief USB Device Capabilities - USB 2.0 Extension Descriptor structure
*
@ -395,7 +388,7 @@ typedef struct {
* The BOS descriptor and capabilities descriptors for LPM.
*/
typedef struct {
usb_dev_bos_desc_t bos;
usb_dev_bos_desc_t bos;
usb_dev_capa_ext_desc_t capa_ext;
} usb_dev_lpm_desc_t;
@ -403,24 +396,23 @@ typedef struct {
* \brief Standard USB Interface Association Descriptor structure
*/
typedef struct {
uint8_t bLength; //!< size of this descriptor in bytes
uint8_t bDescriptorType; //!< INTERFACE descriptor type
uint8_t bFirstInterface; //!< Number of interface
uint8_t bInterfaceCount; //!< value to select alternate setting
uint8_t bFunctionClass; //!< Class code assigned by the USB
uint8_t bFunctionSubClass;//!< Sub-class code assigned by the USB
uint8_t bFunctionProtocol;//!< Protocol code assigned by the USB
uint8_t iFunction; //!< Index of string descriptor
uint8_t bLength; //!< size of this descriptor in bytes
uint8_t bDescriptorType; //!< INTERFACE descriptor type
uint8_t bFirstInterface; //!< Number of interface
uint8_t bInterfaceCount; //!< value to select alternate setting
uint8_t bFunctionClass; //!< Class code assigned by the USB
uint8_t bFunctionSubClass; //!< Sub-class code assigned by the USB
uint8_t bFunctionProtocol; //!< Protocol code assigned by the USB
uint8_t iFunction; //!< Index of string descriptor
} usb_association_desc_t;
/**
* \brief Standard USB configuration descriptor structure
*/
typedef struct {
uint8_t bLength;
uint8_t bDescriptorType;
le16_t wTotalLength;
le16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
@ -428,26 +420,25 @@ typedef struct {
uint8_t bMaxPower;
} usb_conf_desc_t;
#define USB_CONFIG_ATTR_MUST_SET (1 << 7) //!< Must always be set
#define USB_CONFIG_ATTR_BUS_POWERED (0 << 6) //!< Bus-powered
#define USB_CONFIG_ATTR_SELF_POWERED (1 << 6) //!< Self-powered
#define USB_CONFIG_ATTR_REMOTE_WAKEUP (1 << 5) //!< remote wakeup supported
#define USB_CONFIG_ATTR_MUST_SET (1 << 7) //!< Must always be set
#define USB_CONFIG_ATTR_BUS_POWERED (0 << 6) //!< Bus-powered
#define USB_CONFIG_ATTR_SELF_POWERED (1 << 6) //!< Self-powered
#define USB_CONFIG_ATTR_REMOTE_WAKEUP (1 << 5) //!< remote wakeup supported
#define USB_CONFIG_MAX_POWER(ma) (((ma) + 1) / 2) //!< Max power in mA
#define USB_CONFIG_MAX_POWER(ma) (((ma) + 1) / 2) //!< Max power in mA
/**
* \brief Standard USB association descriptor structure
*/
typedef struct {
uint8_t bLength; //!< Size of this descriptor in bytes
uint8_t bDescriptorType; //!< Interface descriptor type
uint8_t bFirstInterface; //!< Number of interface
uint8_t bInterfaceCount; //!< value to select alternate setting
uint8_t bFunctionClass; //!< Class code assigned by the USB
uint8_t bFunctionSubClass; //!< Sub-class code assigned by the USB
uint8_t bFunctionProtocol; //!< Protocol code assigned by the USB
uint8_t iFunction; //!< Index of string descriptor
uint8_t bLength; //!< Size of this descriptor in bytes
uint8_t bDescriptorType; //!< Interface descriptor type
uint8_t bFirstInterface; //!< Number of interface
uint8_t bInterfaceCount; //!< value to select alternate setting
uint8_t bFunctionClass; //!< Class code assigned by the USB
uint8_t bFunctionSubClass; //!< Sub-class code assigned by the USB
uint8_t bFunctionProtocol; //!< Protocol code assigned by the USB
uint8_t iFunction; //!< Index of string descriptor
} usb_iad_desc_t;
/**
@ -473,11 +464,10 @@ typedef struct {
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
le16_t wMaxPacketSize;
le16_t wMaxPacketSize;
uint8_t bInterval;
} usb_ep_desc_t;
/**
* \brief A standard USB string descriptor structure
*/
@ -488,7 +478,7 @@ typedef struct {
typedef struct {
usb_str_desc_t desc;
le16_t string[1];
le16_t string[1];
} usb_str_lgid_desc_t;
COMPILER_PACK_RESET()

View file

@ -50,144 +50,141 @@
#ifdef CDC
#define CDC_CLASS_DEVICE 0x02 //!< USB Communication Device Class
#define CDC_CLASS_COMM 0x02 //!< CDC Communication Class Interface
#define CDC_CLASS_DATA 0x0A //!< CDC Data Class Interface
# define CDC_CLASS_DEVICE 0x02 //!< USB Communication Device Class
# define CDC_CLASS_COMM 0x02 //!< CDC Communication Class Interface
# define CDC_CLASS_DATA 0x0A //!< CDC Data Class Interface
#define CDC_SUBCLASS_DLCM 0x01 //!< Direct Line Control Model
#define CDC_SUBCLASS_ACM 0x02 //!< Abstract Control Model
#define CDC_SUBCLASS_TCM 0x03 //!< Telephone Control Model
#define CDC_SUBCLASS_MCCM 0x04 //!< Multi-Channel Control Model
#define CDC_SUBCLASS_CCM 0x05 //!< CAPI Control Model
#define CDC_SUBCLASS_ETH 0x06 //!< Ethernet Networking Control Model
#define CDC_SUBCLASS_ATM 0x07 //!< ATM Networking Control Model
# define CDC_SUBCLASS_DLCM 0x01 //!< Direct Line Control Model
# define CDC_SUBCLASS_ACM 0x02 //!< Abstract Control Model
# define CDC_SUBCLASS_TCM 0x03 //!< Telephone Control Model
# define CDC_SUBCLASS_MCCM 0x04 //!< Multi-Channel Control Model
# define CDC_SUBCLASS_CCM 0x05 //!< CAPI Control Model
# define CDC_SUBCLASS_ETH 0x06 //!< Ethernet Networking Control Model
# define CDC_SUBCLASS_ATM 0x07 //!< ATM Networking Control Model
#define CDC_PROTOCOL_V25TER 0x01 //!< Common AT commands
# define CDC_PROTOCOL_V25TER 0x01 //!< Common AT commands
#define CDC_PROTOCOL_I430 0x30 //!< ISDN BRI
#define CDC_PROTOCOL_HDLC 0x31 //!< HDLC
#define CDC_PROTOCOL_TRANS 0x32 //!< Transparent
#define CDC_PROTOCOL_Q921M 0x50 //!< Q.921 management protocol
#define CDC_PROTOCOL_Q921 0x51 //!< Q.931 [sic] Data link protocol
#define CDC_PROTOCOL_Q921TM 0x52 //!< Q.921 TEI-multiplexor
#define CDC_PROTOCOL_V42BIS 0x90 //!< Data compression procedures
#define CDC_PROTOCOL_Q931 0x91 //!< Euro-ISDN protocol control
#define CDC_PROTOCOL_V120 0x92 //!< V.24 rate adaption to ISDN
#define CDC_PROTOCOL_CAPI20 0x93 //!< CAPI Commands
#define CDC_PROTOCOL_HOST 0xFD //!< Host based driver
# define CDC_PROTOCOL_I430 0x30 //!< ISDN BRI
# define CDC_PROTOCOL_HDLC 0x31 //!< HDLC
# define CDC_PROTOCOL_TRANS 0x32 //!< Transparent
# define CDC_PROTOCOL_Q921M 0x50 //!< Q.921 management protocol
# define CDC_PROTOCOL_Q921 0x51 //!< Q.931 [sic] Data link protocol
# define CDC_PROTOCOL_Q921TM 0x52 //!< Q.921 TEI-multiplexor
# define CDC_PROTOCOL_V42BIS 0x90 //!< Data compression procedures
# define CDC_PROTOCOL_Q931 0x91 //!< Euro-ISDN protocol control
# define CDC_PROTOCOL_V120 0x92 //!< V.24 rate adaption to ISDN
# define CDC_PROTOCOL_CAPI20 0x93 //!< CAPI Commands
# define CDC_PROTOCOL_HOST 0xFD //!< Host based driver
#define CDC_PROTOCOL_PUFD 0xFE
# define CDC_PROTOCOL_PUFD 0xFE
#define CDC_CS_INTERFACE 0x24 //!< Interface Functional Descriptor
#define CDC_CS_ENDPOINT 0x25 //!< Endpoint Functional Descriptor
# define CDC_CS_INTERFACE 0x24 //!< Interface Functional Descriptor
# define CDC_CS_ENDPOINT 0x25 //!< Endpoint Functional Descriptor
#define CDC_SCS_HEADER 0x00 //!< Header Functional Descriptor
#define CDC_SCS_CALL_MGMT 0x01 //!< Call Management
#define CDC_SCS_ACM 0x02 //!< Abstract Control Management
#define CDC_SCS_UNION 0x06 //!< Union Functional Descriptor
# define CDC_SCS_HEADER 0x00 //!< Header Functional Descriptor
# define CDC_SCS_CALL_MGMT 0x01 //!< Call Management
# define CDC_SCS_ACM 0x02 //!< Abstract Control Management
# define CDC_SCS_UNION 0x06 //!< Union Functional Descriptor
#define USB_REQ_CDC_SEND_ENCAPSULATED_COMMAND 0x00
#define USB_REQ_CDC_GET_ENCAPSULATED_RESPONSE 0x01
#define USB_REQ_CDC_SET_COMM_FEATURE 0x02
#define USB_REQ_CDC_GET_COMM_FEATURE 0x03
#define USB_REQ_CDC_CLEAR_COMM_FEATURE 0x04
#define USB_REQ_CDC_SET_AUX_LINE_STATE 0x10
#define USB_REQ_CDC_SET_HOOK_STATE 0x11
#define USB_REQ_CDC_PULSE_SETUP 0x12
#define USB_REQ_CDC_SEND_PULSE 0x13
#define USB_REQ_CDC_SET_PULSE_TIME 0x14
#define USB_REQ_CDC_RING_AUX_JACK 0x15
#define USB_REQ_CDC_SET_LINE_CODING 0x20
#define USB_REQ_CDC_GET_LINE_CODING 0x21
#define USB_REQ_CDC_SET_CONTROL_LINE_STATE 0x22
#define USB_REQ_CDC_SEND_BREAK 0x23
#define USB_REQ_CDC_SET_RINGER_PARMS 0x30
#define USB_REQ_CDC_GET_RINGER_PARMS 0x31
#define USB_REQ_CDC_SET_OPERATION_PARMS 0x32
#define USB_REQ_CDC_GET_OPERATION_PARMS 0x33
#define USB_REQ_CDC_SET_LINE_PARMS 0x34
#define USB_REQ_CDC_GET_LINE_PARMS 0x35
#define USB_REQ_CDC_DIAL_DIGITS 0x36
#define USB_REQ_CDC_SET_UNIT_PARAMETER 0x37
#define USB_REQ_CDC_GET_UNIT_PARAMETER 0x38
#define USB_REQ_CDC_CLEAR_UNIT_PARAMETER 0x39
#define USB_REQ_CDC_GET_PROFILE 0x3A
#define USB_REQ_CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
#define USB_REQ_CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERNFILTER 0x41
#define USB_REQ_CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERNFILTER 0x42
#define USB_REQ_CDC_SET_ETHERNET_PACKET_FILTER 0x43
#define USB_REQ_CDC_GET_ETHERNET_STATISTIC 0x44
#define USB_REQ_CDC_SET_ATM_DATA_FORMAT 0x50
#define USB_REQ_CDC_GET_ATM_DEVICE_STATISTICS 0x51
#define USB_REQ_CDC_SET_ATM_DEFAULT_VC 0x52
#define USB_REQ_CDC_GET_ATM_VC_STATISTICS 0x53
# define USB_REQ_CDC_SEND_ENCAPSULATED_COMMAND 0x00
# define USB_REQ_CDC_GET_ENCAPSULATED_RESPONSE 0x01
# define USB_REQ_CDC_SET_COMM_FEATURE 0x02
# define USB_REQ_CDC_GET_COMM_FEATURE 0x03
# define USB_REQ_CDC_CLEAR_COMM_FEATURE 0x04
# define USB_REQ_CDC_SET_AUX_LINE_STATE 0x10
# define USB_REQ_CDC_SET_HOOK_STATE 0x11
# define USB_REQ_CDC_PULSE_SETUP 0x12
# define USB_REQ_CDC_SEND_PULSE 0x13
# define USB_REQ_CDC_SET_PULSE_TIME 0x14
# define USB_REQ_CDC_RING_AUX_JACK 0x15
# define USB_REQ_CDC_SET_LINE_CODING 0x20
# define USB_REQ_CDC_GET_LINE_CODING 0x21
# define USB_REQ_CDC_SET_CONTROL_LINE_STATE 0x22
# define USB_REQ_CDC_SEND_BREAK 0x23
# define USB_REQ_CDC_SET_RINGER_PARMS 0x30
# define USB_REQ_CDC_GET_RINGER_PARMS 0x31
# define USB_REQ_CDC_SET_OPERATION_PARMS 0x32
# define USB_REQ_CDC_GET_OPERATION_PARMS 0x33
# define USB_REQ_CDC_SET_LINE_PARMS 0x34
# define USB_REQ_CDC_GET_LINE_PARMS 0x35
# define USB_REQ_CDC_DIAL_DIGITS 0x36
# define USB_REQ_CDC_SET_UNIT_PARAMETER 0x37
# define USB_REQ_CDC_GET_UNIT_PARAMETER 0x38
# define USB_REQ_CDC_CLEAR_UNIT_PARAMETER 0x39
# define USB_REQ_CDC_GET_PROFILE 0x3A
# define USB_REQ_CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
# define USB_REQ_CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERNFILTER 0x41
# define USB_REQ_CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERNFILTER 0x42
# define USB_REQ_CDC_SET_ETHERNET_PACKET_FILTER 0x43
# define USB_REQ_CDC_GET_ETHERNET_STATISTIC 0x44
# define USB_REQ_CDC_SET_ATM_DATA_FORMAT 0x50
# define USB_REQ_CDC_GET_ATM_DEVICE_STATISTICS 0x51
# define USB_REQ_CDC_SET_ATM_DEFAULT_VC 0x52
# define USB_REQ_CDC_GET_ATM_VC_STATISTICS 0x53
// Added bNotification codes according cdc spec 1.1 chapter 6.3
#define USB_REQ_CDC_NOTIFY_RING_DETECT 0x09
#define USB_REQ_CDC_NOTIFY_SERIAL_STATE 0x20
#define USB_REQ_CDC_NOTIFY_CALL_STATE_CHANGE 0x28
#define USB_REQ_CDC_NOTIFY_LINE_STATE_CHANGE 0x29
# define USB_REQ_CDC_NOTIFY_RING_DETECT 0x09
# define USB_REQ_CDC_NOTIFY_SERIAL_STATE 0x20
# define USB_REQ_CDC_NOTIFY_CALL_STATE_CHANGE 0x28
# define USB_REQ_CDC_NOTIFY_LINE_STATE_CHANGE 0x29
# define CDC_CALL_MGMT_SUPPORTED (1 << 0)
# define CDC_CALL_MGMT_OVER_DCI (1 << 1)
# define CDC_ACM_SUPPORT_FEATURE_REQUESTS (1 << 0)
# define CDC_ACM_SUPPORT_LINE_REQUESTS (1 << 1)
# define CDC_ACM_SUPPORT_SENDBREAK_REQUESTS (1 << 2)
# define CDC_ACM_SUPPORT_NOTIFY_REQUESTS (1 << 3)
#define CDC_CALL_MGMT_SUPPORTED (1 << 0)
#define CDC_CALL_MGMT_OVER_DCI (1 << 1)
#define CDC_ACM_SUPPORT_FEATURE_REQUESTS (1 << 0)
#define CDC_ACM_SUPPORT_LINE_REQUESTS (1 << 1)
#define CDC_ACM_SUPPORT_SENDBREAK_REQUESTS (1 << 2)
#define CDC_ACM_SUPPORT_NOTIFY_REQUESTS (1 << 3)
#pragma pack(push,1)
# pragma pack(push, 1)
typedef struct {
le32_t dwDTERate;
le32_t dwDTERate;
uint8_t bCharFormat;
uint8_t bParityType;
uint8_t bDataBits;
} usb_cdc_line_coding_t;
#pragma pack(pop)
# pragma pack(pop)
enum cdc_char_format {
CDC_STOP_BITS_1 = 0, //!< 1 stop bit
CDC_STOP_BITS_1 = 0, //!< 1 stop bit
CDC_STOP_BITS_1_5 = 1, //!< 1.5 stop bits
CDC_STOP_BITS_2 = 2, //!< 2 stop bits
CDC_STOP_BITS_2 = 2, //!< 2 stop bits
};
enum cdc_parity {
CDC_PAR_NONE = 0, //!< No parity
CDC_PAR_ODD = 1, //!< Odd parity
CDC_PAR_EVEN = 2, //!< Even parity
CDC_PAR_MARK = 3, //!< Parity forced to 0 (space)
CDC_PAR_NONE = 0, //!< No parity
CDC_PAR_ODD = 1, //!< Odd parity
CDC_PAR_EVEN = 2, //!< Even parity
CDC_PAR_MARK = 3, //!< Parity forced to 0 (space)
CDC_PAR_SPACE = 4, //!< Parity forced to 1 (mark)
};
typedef struct {
uint16_t value;
} usb_cdc_control_signal_t;
#define CDC_CTRL_SIGNAL_ACTIVATE_CARRIER (1 << 1)
#define CDC_CTRL_SIGNAL_DTE_PRESENT (1 << 0)
# define CDC_CTRL_SIGNAL_ACTIVATE_CARRIER (1 << 1)
# define CDC_CTRL_SIGNAL_DTE_PRESENT (1 << 0)
typedef struct {
uint8_t bmRequestType;
uint8_t bNotification;
le16_t wValue;
le16_t wIndex;
le16_t wLength;
le16_t wValue;
le16_t wIndex;
le16_t wLength;
} usb_cdc_notify_msg_t;
typedef struct {
usb_cdc_notify_msg_t header;
le16_t value;
le16_t value;
} usb_cdc_notify_serial_state_t;
#define CDC_SERIAL_STATE_DCD CPU_TO_LE16((1<<0))
#define CDC_SERIAL_STATE_DSR CPU_TO_LE16((1<<1))
#define CDC_SERIAL_STATE_BREAK CPU_TO_LE16((1<<2))
#define CDC_SERIAL_STATE_RING CPU_TO_LE16((1<<3))
#define CDC_SERIAL_STATE_FRAMING CPU_TO_LE16((1<<4))
#define CDC_SERIAL_STATE_PARITY CPU_TO_LE16((1<<5))
#define CDC_SERIAL_STATE_OVERRUN CPU_TO_LE16((1<<6))
# define CDC_SERIAL_STATE_DCD CPU_TO_LE16((1 << 0))
# define CDC_SERIAL_STATE_DSR CPU_TO_LE16((1 << 1))
# define CDC_SERIAL_STATE_BREAK CPU_TO_LE16((1 << 2))
# define CDC_SERIAL_STATE_RING CPU_TO_LE16((1 << 3))
# define CDC_SERIAL_STATE_FRAMING CPU_TO_LE16((1 << 4))
# define CDC_SERIAL_STATE_PARITY CPU_TO_LE16((1 << 5))
# define CDC_SERIAL_STATE_OVERRUN CPU_TO_LE16((1 << 6))
#endif
#endif // _USB_PROTOCOL_CDC_H_
#endif // _USB_PROTOCOL_CDC_H_

View file

@ -58,64 +58,62 @@
//! \name Possible Class value
//@{
#define HID_CLASS 0x03
#define HID_CLASS 0x03
//@}
//! \name Possible SubClass value
//@{
//! Interface subclass NO support BOOT protocol
#define HID_SUB_CLASS_NOBOOT 0x00
#define HID_SUB_CLASS_NOBOOT 0x00
//! Interface subclass support BOOT protocol
#define HID_SUB_CLASS_BOOT 0x01
#define HID_SUB_CLASS_BOOT 0x01
//@}
//! \name Possible protocol value
//@{
//! Protocol generic standard
#define HID_PROTOCOL_GENERIC 0x00
#define HID_PROTOCOL_GENERIC 0x00
//! Protocol keyboard standard
#define HID_PROTOCOL_KEYBOARD 0x01
#define HID_PROTOCOL_KEYBOARD 0x01
//! Protocol mouse standard
#define HID_PROTOCOL_MOUSE 0x02
#define HID_PROTOCOL_MOUSE 0x02
//@}
//! \brief Hid USB requests (bRequest)
enum usb_reqid_hid {
USB_REQ_HID_GET_REPORT = 0x01,
USB_REQ_HID_GET_IDLE = 0x02,
USB_REQ_HID_GET_REPORT = 0x01,
USB_REQ_HID_GET_IDLE = 0x02,
USB_REQ_HID_GET_PROTOCOL = 0x03,
USB_REQ_HID_SET_REPORT = 0x09,
USB_REQ_HID_SET_IDLE = 0x0A,
USB_REQ_HID_SET_REPORT = 0x09,
USB_REQ_HID_SET_IDLE = 0x0A,
USB_REQ_HID_SET_PROTOCOL = 0x0B,
};
//! \brief HID USB descriptor types
enum usb_descriptor_type_hid {
USB_DT_HID = 0x21,
USB_DT_HID_REPORT = 0x22,
USB_DT_HID = 0x21,
USB_DT_HID_REPORT = 0x22,
USB_DT_HID_PHYSICAL = 0x23,
};
//! \brief HID Type for report descriptor
enum usb_hid_item_report_type {
USB_HID_ITEM_REPORT_TYPE_MAIN = 0,
USB_HID_ITEM_REPORT_TYPE_MAIN = 0,
USB_HID_ITEM_REPORT_TYPE_GLOBAL = 1,
USB_HID_ITEM_REPORT_TYPE_LOCAL = 2,
USB_HID_ITEM_REPORT_TYPE_LONG = 3,
USB_HID_ITEM_REPORT_TYPE_LOCAL = 2,
USB_HID_ITEM_REPORT_TYPE_LONG = 3,
};
//! \brief HID report type
enum usb_hid_report_type {
USB_HID_REPORT_TYPE_INPUT = 1,
USB_HID_REPORT_TYPE_OUTPUT = 2,
USB_HID_REPORT_TYPE_INPUT = 1,
USB_HID_REPORT_TYPE_OUTPUT = 2,
USB_HID_REPORT_TYPE_FEATURE = 3,
};
//! \brief HID protocol
enum usb_hid_protocol {
USB_HID_PROCOTOL_BOOT = 0,
USB_HID_PROCOTOL_BOOT = 0,
USB_HID_PROCOTOL_REPORT = 1,
};
@ -123,197 +121,196 @@ COMPILER_PACK_SET(1)
//! \brief HID Descriptor
typedef struct {
uint8_t bLength; //!< Size of this descriptor in bytes
uint8_t bDescriptorType; //!< HID descriptor type
le16_t bcdHID; //!< Binary Coded Decimal Spec. release
uint8_t bCountryCode; //!< Hardware target country
uint8_t bNumDescriptors; //!< Number of HID class descriptors to follow
uint8_t bRDescriptorType; //!< Report descriptor type
le16_t wDescriptorLength; //!< Total length of Report descriptor
uint8_t bLength; //!< Size of this descriptor in bytes
uint8_t bDescriptorType; //!< HID descriptor type
le16_t bcdHID; //!< Binary Coded Decimal Spec. release
uint8_t bCountryCode; //!< Hardware target country
uint8_t bNumDescriptors; //!< Number of HID class descriptors to follow
uint8_t bRDescriptorType; //!< Report descriptor type
le16_t wDescriptorLength; //!< Total length of Report descriptor
} usb_hid_descriptor_t;
COMPILER_PACK_RESET()
//! \name HID Report type
//! Used by SETUP_HID_GET_REPORT & SETUP_HID_SET_REPORT
//! @{
#define REPORT_TYPE_INPUT 0x01
#define REPORT_TYPE_OUTPUT 0x02
#define REPORT_TYPE_FEATURE 0x03
//! @}
//! \name HID Report type
//! Used by SETUP_HID_GET_REPORT & SETUP_HID_SET_REPORT
//! @{
#define REPORT_TYPE_INPUT 0x01
#define REPORT_TYPE_OUTPUT 0x02
#define REPORT_TYPE_FEATURE 0x03
//! @}
//! \name Constants of field DESCRIPTOR_HID
//! @{
//! \name Constants of field DESCRIPTOR_HID
//! @{
//! Numeric expression identifying the HID Class
//! Specification release (here V1.11)
#define USB_HID_BDC_V1_11 0x0111
#define USB_HID_BDC_V1_11 0x0111
//! Numeric expression specifying the number of class descriptors
//! Note: Always at least one i.e. Report descriptor.
#define USB_HID_NUM_DESC 0x01
#define USB_HID_NUM_DESC 0x01
//! \name Country code
//! @{
#define USB_HID_NO_COUNTRY_CODE 0 // Not Supported
#define USB_HID_COUNTRY_ARABIC 1 // Arabic
#define USB_HID_COUNTRY_BELGIAN 2 // Belgian
#define USB_HID_COUNTRY_CANADIAN_BILINGUAL 3 // Canadian-Bilingual
#define USB_HID_COUNTRY_CANADIAN_FRENCH 4 // Canadian-French
#define USB_HID_COUNTRY_CZECH_REPUBLIC 5 // Czech Republic
#define USB_HID_COUNTRY_DANISH 6 // Danish
#define USB_HID_COUNTRY_FINNISH 7 // Finnish
#define USB_HID_COUNTRY_FRENCH 8 // French
#define USB_HID_COUNTRY_GERMAN 9 // German
#define USB_HID_COUNTRY_GREEK 10 // Greek
#define USB_HID_COUNTRY_HEBREW 11 // Hebrew
#define USB_HID_COUNTRY_HUNGARY 12 // Hungary
#define USB_HID_COUNTRY_INTERNATIONAL_ISO 13 // International (ISO)
#define USB_HID_COUNTRY_ITALIAN 14 // Italian
#define USB_HID_COUNTRY_JAPAN_KATAKANA 15 // Japan (Katakana)
#define USB_HID_COUNTRY_KOREAN 16 // Korean
#define USB_HID_COUNTRY_LATIN_AMERICAN 17 // Latin American
#define USB_HID_COUNTRY_NETHERLANDS_DUTCH 18 // Netherlands/Dutch
#define USB_HID_COUNTRY_NORWEGIAN 19 // Norwegian
#define USB_HID_COUNTRY_PERSIAN_FARSI 20 // Persian (Farsi)
#define USB_HID_COUNTRY_POLAND 21 // Poland
#define USB_HID_COUNTRY_PORTUGUESE 22 // Portuguese
#define USB_HID_COUNTRY_RUSSIA 23 // Russia
#define USB_HID_COUNTRY_SLOVAKIA 24 // Slovakia
#define USB_HID_COUNTRY_SPANISH 25 // Spanish
#define USB_HID_COUNTRY_SWEDISH 26 // Swedish
#define USB_HID_COUNTRY_SWISS_FRENCH 27 // Swiss/French
#define USB_HID_COUNTRY_SWISS_GERMAN 28 // Swiss/German
#define USB_HID_COUNTRY_SWITZERLAND 29 // Switzerland
#define USB_HID_COUNTRY_TAIWAN 30 // Taiwan
#define USB_HID_COUNTRY_TURKISH_Q 31 // Turkish-Q
#define USB_HID_COUNTRY_UK 32 // UK
#define USB_HID_COUNTRY_US 33 // US
#define USB_HID_COUNTRY_YUGOSLAVIA 34 // Yugoslavia
#define USB_HID_COUNTRY_TURKISH_F 35 // Turkish-F
//! @}
//! @}
//! @}
//! \name HID KEYS values
//! \name Country code
//! @{
#define HID_A 0x04
#define HID_B 0x05
#define HID_C 0x06
#define HID_D 0x07
#define HID_E 0x08
#define HID_F 0x09
#define HID_G 0x0A
#define HID_H 0x0B
#define HID_I 0x0C
#define HID_J 0x0D
#define HID_K 0x0E
#define HID_L 0x0F
#define HID_M 0x10
#define HID_N 0x11
#define HID_O 0x12
#define HID_P 0x13
#define HID_Q 0x14
#define HID_R 0x15
#define HID_S 0x16
#define HID_T 0x17
#define HID_U 0x18
#define HID_V 0x19
#define HID_W 0x1A
#define HID_X 0x1B
#define HID_Y 0x1C
#define HID_Z 0x1D
#define HID_1 30
#define HID_2 31
#define HID_3 32
#define HID_4 33
#define HID_5 34
#define HID_6 35
#define HID_7 36
#define HID_8 37
#define HID_9 38
#define HID_0 39
#define HID_ENTER 40
#define HID_ESCAPE 41
#define HID_BACKSPACE 42
#define HID_TAB 43
#define HID_SPACEBAR 44
#define HID_UNDERSCORE 45
#define HID_PLUS 46
#define HID_OPEN_BRACKET 47 // {
#define HID_CLOSE_BRACKET 48 // }
#define HID_BACKSLASH 49
#define HID_ASH 50 // # ~
#define HID_COLON 51 // ; :
#define HID_QUOTE 52 // ' "
#define HID_TILDE 53
#define HID_COMMA 54
#define HID_DOT 55
#define HID_SLASH 56
#define HID_CAPS_LOCK 57
#define HID_F1 58
#define HID_F2 59
#define HID_F3 60
#define HID_F4 61
#define HID_F5 62
#define HID_F6 63
#define HID_F7 64
#define HID_F8 65
#define HID_F9 66
#define HID_F10 67
#define HID_F11 68
#define HID_F12 69
#define HID_PRINTSCREEN 70
#define HID_SCROLL_LOCK 71
#define HID_PAUSE 72
#define HID_INSERT 73
#define HID_HOME 74
#define HID_PAGEUP 75
#define HID_DELETE 76
#define HID_END 77
#define HID_PAGEDOWN 78
#define HID_RIGHT 79
#define HID_LEFT 80
#define HID_DOWN 81
#define HID_UP 82
#define HID_KEYPAD_NUM_LOCK 83
#define HID_KEYPAD_DIVIDE 84
#define HID_KEYPAD_AT 85
#define HID_KEYPAD_MULTIPLY 85
#define HID_KEYPAD_MINUS 86
#define HID_KEYPAD_PLUS 87
#define HID_KEYPAD_ENTER 88
#define HID_KEYPAD_1 89
#define HID_KEYPAD_2 90
#define HID_KEYPAD_3 91
#define HID_KEYPAD_4 92
#define HID_KEYPAD_5 93
#define HID_KEYPAD_6 94
#define HID_KEYPAD_7 95
#define HID_KEYPAD_8 96
#define HID_KEYPAD_9 97
#define HID_KEYPAD_0 98
//! \name HID modifier values
//! @{
#define HID_MODIFIER_NONE 0x00
#define HID_MODIFIER_LEFT_CTRL 0x01
#define HID_MODIFIER_LEFT_SHIFT 0x02
#define HID_MODIFIER_LEFT_ALT 0x04
#define HID_MODIFIER_LEFT_UI 0x08
#define HID_MODIFIER_RIGHT_CTRL 0x10
#define HID_MODIFIER_RIGHT_SHIFT 0x20
#define HID_MODIFIER_RIGHT_ALT 0x40
#define HID_MODIFIER_RIGHT_UI 0x80
//! @}
#define USB_HID_NO_COUNTRY_CODE 0 // Not Supported
#define USB_HID_COUNTRY_ARABIC 1 // Arabic
#define USB_HID_COUNTRY_BELGIAN 2 // Belgian
#define USB_HID_COUNTRY_CANADIAN_BILINGUAL 3 // Canadian-Bilingual
#define USB_HID_COUNTRY_CANADIAN_FRENCH 4 // Canadian-French
#define USB_HID_COUNTRY_CZECH_REPUBLIC 5 // Czech Republic
#define USB_HID_COUNTRY_DANISH 6 // Danish
#define USB_HID_COUNTRY_FINNISH 7 // Finnish
#define USB_HID_COUNTRY_FRENCH 8 // French
#define USB_HID_COUNTRY_GERMAN 9 // German
#define USB_HID_COUNTRY_GREEK 10 // Greek
#define USB_HID_COUNTRY_HEBREW 11 // Hebrew
#define USB_HID_COUNTRY_HUNGARY 12 // Hungary
#define USB_HID_COUNTRY_INTERNATIONAL_ISO 13 // International (ISO)
#define USB_HID_COUNTRY_ITALIAN 14 // Italian
#define USB_HID_COUNTRY_JAPAN_KATAKANA 15 // Japan (Katakana)
#define USB_HID_COUNTRY_KOREAN 16 // Korean
#define USB_HID_COUNTRY_LATIN_AMERICAN 17 // Latin American
#define USB_HID_COUNTRY_NETHERLANDS_DUTCH 18 // Netherlands/Dutch
#define USB_HID_COUNTRY_NORWEGIAN 19 // Norwegian
#define USB_HID_COUNTRY_PERSIAN_FARSI 20 // Persian (Farsi)
#define USB_HID_COUNTRY_POLAND 21 // Poland
#define USB_HID_COUNTRY_PORTUGUESE 22 // Portuguese
#define USB_HID_COUNTRY_RUSSIA 23 // Russia
#define USB_HID_COUNTRY_SLOVAKIA 24 // Slovakia
#define USB_HID_COUNTRY_SPANISH 25 // Spanish
#define USB_HID_COUNTRY_SWEDISH 26 // Swedish
#define USB_HID_COUNTRY_SWISS_FRENCH 27 // Swiss/French
#define USB_HID_COUNTRY_SWISS_GERMAN 28 // Swiss/German
#define USB_HID_COUNTRY_SWITZERLAND 29 // Switzerland
#define USB_HID_COUNTRY_TAIWAN 30 // Taiwan
#define USB_HID_COUNTRY_TURKISH_Q 31 // Turkish-Q
#define USB_HID_COUNTRY_UK 32 // UK
#define USB_HID_COUNTRY_US 33 // US
#define USB_HID_COUNTRY_YUGOSLAVIA 34 // Yugoslavia
#define USB_HID_COUNTRY_TURKISH_F 35 // Turkish-F
//! @}
//! @}
//! @}
//! \name HID KEYS values
//! @{
#define HID_LED_NUM_LOCK (1<<0)
#define HID_LED_CAPS_LOCK (1<<1)
#define HID_LED_SCROLL_LOCK (1<<2)
#define HID_LED_COMPOSE (1<<3)
#define HID_LED_KANA (1<<4)
#define HID_A 0x04
#define HID_B 0x05
#define HID_C 0x06
#define HID_D 0x07
#define HID_E 0x08
#define HID_F 0x09
#define HID_G 0x0A
#define HID_H 0x0B
#define HID_I 0x0C
#define HID_J 0x0D
#define HID_K 0x0E
#define HID_L 0x0F
#define HID_M 0x10
#define HID_N 0x11
#define HID_O 0x12
#define HID_P 0x13
#define HID_Q 0x14
#define HID_R 0x15
#define HID_S 0x16
#define HID_T 0x17
#define HID_U 0x18
#define HID_V 0x19
#define HID_W 0x1A
#define HID_X 0x1B
#define HID_Y 0x1C
#define HID_Z 0x1D
#define HID_1 30
#define HID_2 31
#define HID_3 32
#define HID_4 33
#define HID_5 34
#define HID_6 35
#define HID_7 36
#define HID_8 37
#define HID_9 38
#define HID_0 39
#define HID_ENTER 40
#define HID_ESCAPE 41
#define HID_BACKSPACE 42
#define HID_TAB 43
#define HID_SPACEBAR 44
#define HID_UNDERSCORE 45
#define HID_PLUS 46
#define HID_OPEN_BRACKET 47 // {
#define HID_CLOSE_BRACKET 48 // }
#define HID_BACKSLASH 49
#define HID_ASH 50 // # ~
#define HID_COLON 51 // ; :
#define HID_QUOTE 52 // ' "
#define HID_TILDE 53
#define HID_COMMA 54
#define HID_DOT 55
#define HID_SLASH 56
#define HID_CAPS_LOCK 57
#define HID_F1 58
#define HID_F2 59
#define HID_F3 60
#define HID_F4 61
#define HID_F5 62
#define HID_F6 63
#define HID_F7 64
#define HID_F8 65
#define HID_F9 66
#define HID_F10 67
#define HID_F11 68
#define HID_F12 69
#define HID_PRINTSCREEN 70
#define HID_SCROLL_LOCK 71
#define HID_PAUSE 72
#define HID_INSERT 73
#define HID_HOME 74
#define HID_PAGEUP 75
#define HID_DELETE 76
#define HID_END 77
#define HID_PAGEDOWN 78
#define HID_RIGHT 79
#define HID_LEFT 80
#define HID_DOWN 81
#define HID_UP 82
#define HID_KEYPAD_NUM_LOCK 83
#define HID_KEYPAD_DIVIDE 84
#define HID_KEYPAD_AT 85
#define HID_KEYPAD_MULTIPLY 85
#define HID_KEYPAD_MINUS 86
#define HID_KEYPAD_PLUS 87
#define HID_KEYPAD_ENTER 88
#define HID_KEYPAD_1 89
#define HID_KEYPAD_2 90
#define HID_KEYPAD_3 91
#define HID_KEYPAD_4 92
#define HID_KEYPAD_5 93
#define HID_KEYPAD_6 94
#define HID_KEYPAD_7 95
#define HID_KEYPAD_8 96
#define HID_KEYPAD_9 97
#define HID_KEYPAD_0 98
//! \name HID modifier values
//! @{
#define HID_MODIFIER_NONE 0x00
#define HID_MODIFIER_LEFT_CTRL 0x01
#define HID_MODIFIER_LEFT_SHIFT 0x02
#define HID_MODIFIER_LEFT_ALT 0x04
#define HID_MODIFIER_LEFT_UI 0x08
#define HID_MODIFIER_RIGHT_CTRL 0x10
#define HID_MODIFIER_RIGHT_SHIFT 0x20
#define HID_MODIFIER_RIGHT_ALT 0x40
#define HID_MODIFIER_RIGHT_UI 0x80
//! @}
//! @}
#endif // _USB_PROTOCOL_HID_H_
//! \name HID KEYS values
//! @{
#define HID_LED_NUM_LOCK (1 << 0)
#define HID_LED_CAPS_LOCK (1 << 1)
#define HID_LED_SCROLL_LOCK (1 << 2)
#define HID_LED_COMPOSE (1 << 3)
#define HID_LED_KANA (1 << 4)
//! @}
#endif // _USB_PROTOCOL_HID_H_

View file

@ -2,58 +2,42 @@
#include "string.h"
#include "usb_util.h"
char digit(int d, int radix)
{
if (d < 10)
{
char digit(int d, int radix) {
if (d < 10) {
return d + '0';
}
else
{
} else {
return d - 10 + 'A';
}
}
int UTIL_ltoa_radix(int64_t value, char *dest, int radix)
{
int64_t original = value; //save original value
char buf[25] = "";
int c = sizeof(buf)-1;
int last = c;
int d;
int size;
int UTIL_ltoa_radix(int64_t value, char *dest, int radix) {
int64_t original = value; // save original value
char buf[25] = "";
int c = sizeof(buf) - 1;
int last = c;
int d;
int size;
if (value < 0) //if it's negative, take the absolute value
if (value < 0) // if it's negative, take the absolute value
value = -value;
do //write least significant digit of value that's left
do // write least significant digit of value that's left
{
d = (value % radix);
d = (value % radix);
buf[--c] = digit(d, radix);
value /= radix;
} while (value);
if (original < 0)
buf[--c] = '-';
if (original < 0) buf[--c] = '-';
size = last - c + 1; //includes null at end
size = last - c + 1; // includes null at end
memcpy(dest, &buf[c], last - c + 1);
return (size - 1); //without null termination
return (size - 1); // without null termination
}
int UTIL_ltoa(int64_t value, char *dest)
{
return UTIL_ltoa_radix(value, dest, 10);
}
int UTIL_ltoa(int64_t value, char *dest) { return UTIL_ltoa_radix(value, dest, 10); }
int UTIL_itoa(int value, char *dest)
{
return UTIL_ltoa_radix((int64_t)value, dest, 10);
}
int UTIL_utoa(uint32_t value, char *dest)
{
return UTIL_ltoa_radix((int64_t)value, dest, 10);
}
int UTIL_itoa(int value, char *dest) { return UTIL_ltoa_radix((int64_t)value, dest, 10); }
int UTIL_utoa(uint32_t value, char *dest) { return UTIL_ltoa_radix((int64_t)value, dest, 10); }

View file

@ -6,5 +6,4 @@ int UTIL_ltoa(int64_t value, char *dest);
int UTIL_itoa(int value, char *dest);
int UTIL_utoa(uint32_t value, char *dest);
#endif //_USB_UTIL_H_
#endif //_USB_UTIL_H_

View file

@ -5,4 +5,3 @@ void wait_ms(uint64_t msec);
void wait_us(uint16_t usec);
#endif

View file

@ -29,31 +29,31 @@ static uint8_t bluefruit_keyboard_leds = 0;
static void bluefruit_serial_send(uint8_t);
void bluefruit_keyboard_print_report(report_keyboard_t *report)
{
void bluefruit_keyboard_print_report(report_keyboard_t *report) {
if (!debug_keyboard) return;
dprintf("keys: "); for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) { debug_hex8(report->keys[i]); dprintf(" "); }
dprintf(" mods: "); debug_hex8(report->mods);
dprintf(" reserved: "); debug_hex8(report->reserved);
dprintf("keys: ");
for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
debug_hex8(report->keys[i]);
dprintf(" ");
}
dprintf(" mods: ");
debug_hex8(report->mods);
dprintf(" reserved: ");
debug_hex8(report->reserved);
dprintf("\n");
}
#ifdef BLUEFRUIT_TRACE_SERIAL
static void bluefruit_trace_header()
{
static void bluefruit_trace_header() {
dprintf("+------------------------------------+\n");
dprintf("| HID report to Bluefruit via serial |\n");
dprintf("+------------------------------------+\n|");
}
static void bluefruit_trace_footer()
{
dprintf("|\n+------------------------------------+\n\n");
}
static void bluefruit_trace_footer() { dprintf("|\n+------------------------------------+\n\n"); }
#endif
static void bluefruit_serial_send(uint8_t data)
{
static void bluefruit_serial_send(uint8_t data) {
#ifdef BLUEFRUIT_TRACE_SERIAL
dprintf(" ");
debug_hex8(data);
@ -67,53 +67,38 @@ static void bluefruit_serial_send(uint8_t data)
*------------------------------------------------------------------*/
static uint8_t keyboard_leds(void);
static void send_keyboard(report_keyboard_t *report);
static void send_mouse(report_mouse_t *report);
static void send_system(uint16_t data);
static void send_consumer(uint16_t data);
static void send_keyboard(report_keyboard_t *report);
static void send_mouse(report_mouse_t *report);
static void send_system(uint16_t data);
static void send_consumer(uint16_t data);
void sendString(char string[], int length) {
for(int i = 0; i < length; i++) {
for (int i = 0; i < length; i++) {
serial_send(string[i]);
}
}
static host_driver_t driver = {
keyboard_leds,
send_keyboard,
send_mouse,
send_system,
send_consumer
};
static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
host_driver_t *bluefruit_driver(void)
{
return &driver;
}
host_driver_t *bluefruit_driver(void) { return &driver; }
static uint8_t keyboard_leds(void) {
return bluefruit_keyboard_leds;
}
static uint8_t keyboard_leds(void) { return bluefruit_keyboard_leds; }
static void send_keyboard(report_keyboard_t *report)
{
#ifdef BLUEFRUIT_TRACE_SERIAL
static void send_keyboard(report_keyboard_t *report) {
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_header();
#endif
bluefruit_serial_send(0xFD);
for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) {
bluefruit_serial_send(report->raw[i]);
}
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_footer();
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_footer();
#endif
}
static void send_mouse(report_mouse_t *report)
{
#ifdef BLUEFRUIT_TRACE_SERIAL
static void send_mouse(report_mouse_t *report) {
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_header();
#endif
bluefruit_serial_send(0xFD);
@ -122,17 +107,15 @@ static void send_mouse(report_mouse_t *report)
bluefruit_serial_send(report->buttons);
bluefruit_serial_send(report->x);
bluefruit_serial_send(report->y);
bluefruit_serial_send(report->v); // should try sending the wheel v here
bluefruit_serial_send(report->h); // should try sending the wheel h here
bluefruit_serial_send(report->v); // should try sending the wheel v here
bluefruit_serial_send(report->h); // should try sending the wheel h here
bluefruit_serial_send(0x00);
#ifdef BLUEFRUIT_TRACE_SERIAL
bluefruit_trace_footer();
#endif
}
static void send_system(uint16_t data)
{
}
static void send_system(uint16_t data) {}
/*
+-----------------+-------------------+-------+
@ -153,48 +136,28 @@ static void send_system(uint16_t data)
| Stop | 00000000 00010000 | 00 10 |
+-------------------------------------+-------+
*/
#define CONSUMER2BLUEFRUIT(usage) \
(usage == AUDIO_MUTE ? 0x0000 : \
(usage == AUDIO_VOL_UP ? 0x1000 : \
(usage == AUDIO_VOL_DOWN ? 0x2000 : \
(usage == TRANSPORT_NEXT_TRACK ? 0x0002 : \
(usage == TRANSPORT_PREV_TRACK ? 0x0004 : \
(usage == TRANSPORT_STOP ? 0x0010 : \
(usage == TRANSPORT_STOP_EJECT ? 0x0000 : \
(usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : \
(usage == AL_CC_CONFIG ? 0x0000 : \
(usage == AL_EMAIL ? 0x0000 : \
(usage == AL_CALCULATOR ? 0x0000 : \
(usage == AL_LOCAL_BROWSER ? 0x0000 : \
(usage == AC_SEARCH ? 0x0400 : \
(usage == AC_HOME ? 0x0100 : \
(usage == AC_BACK ? 0x0000 : \
(usage == AC_FORWARD ? 0x0000 : \
(usage == AC_STOP ? 0x0000 : \
(usage == AC_REFRESH ? 0x0000 : \
(usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
#define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
static void send_consumer(uint16_t data)
{
static void send_consumer(uint16_t data) {
static uint16_t last_data = 0;
if (data == last_data) return;
last_data = data;
uint16_t bitmap = CONSUMER2BLUEFRUIT(data);
#ifdef BLUEFRUIT_TRACE_SERIAL
dprintf("\nData: ");
debug_hex16(data);
dprintf("; bitmap: ");
debug_hex16(bitmap);
#ifdef BLUEFRUIT_TRACE_SERIAL
dprintf("\nData: ");
debug_hex16(data);
dprintf("; bitmap: ");
debug_hex16(bitmap);
dprintf("\n");
bluefruit_trace_header();
#endif
bluefruit_serial_send(0xFD);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x02);
bluefruit_serial_send((bitmap>>8)&0xFF);
bluefruit_serial_send(bitmap&0xFF);
bluefruit_serial_send((bitmap >> 8) & 0xFF);
bluefruit_serial_send(bitmap & 0xFF);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x00);
bluefruit_serial_send(0x00);

View file

@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "host_driver.h"
host_driver_t *bluefruit_driver(void);
#endif

View file

@ -34,16 +34,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "bluefruit.h"
#include "pjrc.h"
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define HOST_DRIVER_NOT_SET 0
#define BLUEFRUIT_HOST_DRIVER 1
#define PJRC_HOST_DRIVER 2
int main(void)
{
#define HOST_DRIVER_NOT_SET 0
#define BLUEFRUIT_HOST_DRIVER 1
#define PJRC_HOST_DRIVER 2
int main(void) {
CPU_PRESCALE(0);
// DDRD = _BV(PD5);
@ -58,7 +55,6 @@ int main(void)
// _delay_ms(2000);
// while (!usb_configured()) /* wait */
keyboard_setup();
dprintf("Initializing keyboard...\n");
@ -76,11 +72,11 @@ int main(void)
// DDRB = _BV(PB6);
// PORTB |= _BV(PB6);
dprintf("Setting host driver to bluefruit...\n");
host_set_driver(bluefruit_driver());
dprintf("Setting host driver to bluefruit...\n");
host_set_driver(bluefruit_driver());
dprintf("Initializing serial...\n");
serial_init();
dprintf("Initializing serial...\n");
serial_init();
// char swpa[] = "+++\r\n";
// for (int i = 0; i < 5; i++) {
@ -101,39 +97,38 @@ int main(void)
// serial_send(swpa[i]);
// }
// wait an extra second for the PC's operating system
// to load drivers and do whatever it does to actually
// be ready for input
_delay_ms(1000);
// PORTD = ~_BV(PD5);
dprintf("Starting main loop");
while (1) {
keyboard_task();
}
// wait an extra second for the PC's operating system
// to load drivers and do whatever it does to actually
// be ready for input
_delay_ms(1000);
// PORTD = ~_BV(PD5);
dprintf("Starting main loop");
while (1) {
keyboard_task();
}
// } else {
// // I'm not smart enough to get this done with LUFA - BCG
// dprintf("Setting host driver to PJRC...\n");
// host_set_driver(pjrc_driver());
// #ifdef SLEEP_LED_ENABLE
// sleep_led_init();
// #endif
// // wait an extra second for the PC's operating system
// // to load drivers and do whatever it does to actually
// // be ready for input
// _delay_ms(1000);
// PORTB = ~_BV(PB0);
// dprintf("Starting main loop");
// while (1) {
// while (suspend) {
// suspend_power_down();
// if (remote_wakeup && suspend_wakeup_condition()) {
// usb_remote_wakeup();
// }
// }
// keyboard_task();
// }
// }
// } else {
// // I'm not smart enough to get this done with LUFA - BCG
// dprintf("Setting host driver to PJRC...\n");
// host_set_driver(pjrc_driver());
// #ifdef SLEEP_LED_ENABLE
// sleep_led_init();
// #endif
// // wait an extra second for the PC's operating system
// // to load drivers and do whatever it does to actually
// // be ready for input
// _delay_ms(1000);
// PORTB = ~_BV(PB0);
// dprintf("Starting main loop");
// while (1) {
// while (suspend) {
// suspend_power_down();
// if (remote_wakeup && suspend_wakeup_condition()) {
// usb_remote_wakeup();
// }
// }
// keyboard_task();
// }
// }
}

View file

@ -2,7 +2,7 @@
#include "stddef.h"
#include "inttypes.h"
#define ATTR_PACKED __attribute__ ((packed))
#define ATTR_PACKED __attribute__((packed))
/** Concatenates the given input into a single token, via the C Preprocessor.
*
* \param[in] x First item to concatenate.
@ -10,7 +10,7 @@
*
* \return Concatenated version of the input.
*/
#define CONCAT(x, y) x ## y
#define CONCAT(x, y) x##y
/** CConcatenates the given input into a single token after macro expansion, via the C Preprocessor.
*
@ -19,8 +19,8 @@
*
* \return Concatenated version of the expanded input.
*/
#define CONCAT_EXPANDED(x, y) CONCAT(x, y)
#define CPU_TO_LE16(x) (x)
#define CONCAT_EXPANDED(x, y) CONCAT(x, y)
#define CPU_TO_LE16(x) (x)
// We don't need anything from the following files, or we have defined it already
#define __LUFA_COMMON_H__

View file

@ -33,19 +33,19 @@
#include "debug.h"
#include "printf.h"
#ifdef SLEEP_LED_ENABLE
#include "sleep_led.h"
# include "sleep_led.h"
#endif
#ifdef SERIAL_LINK_ENABLE
#include "serial_link/system/serial_link.h"
# include "serial_link/system/serial_link.h"
#endif
#ifdef VISUALIZER_ENABLE
#include "visualizer/visualizer.h"
# include "visualizer/visualizer.h"
#endif
#ifdef MIDI_ENABLE
#include "qmk_midi.h"
# include "qmk_midi.h"
#endif
#ifdef STM32_EEPROM_ENABLE
#include "eeprom_stm32.h"
# include "eeprom_stm32.h"
#endif
#include "suspend.h"
#include "wait.h"
@ -57,19 +57,13 @@
/* declarations */
uint8_t keyboard_leds(void);
void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
void send_system(uint16_t data);
void send_consumer(uint16_t data);
void send_keyboard(report_keyboard_t *report);
void send_mouse(report_mouse_t *report);
void send_system(uint16_t data);
void send_consumer(uint16_t data);
/* host struct */
host_driver_t chibios_driver = {
keyboard_leds,
send_keyboard,
send_mouse,
send_system,
send_consumer
};
host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
#ifdef VIRTSER_ENABLE
void virtser_task(void);
@ -103,127 +97,123 @@ void console_task(void);
// }
// }
/* Main thread
*/
int main(void) {
/* ChibiOS/RT init */
halInit();
chSysInit();
/* ChibiOS/RT init */
halInit();
chSysInit();
#ifdef STM32_EEPROM_ENABLE
EEPROM_Init();
EEPROM_Init();
#endif
// TESTING
// chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
// TESTING
// chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
keyboard_setup();
keyboard_setup();
/* Init USB */
init_usb_driver(&USB_DRIVER);
/* Init USB */
init_usb_driver(&USB_DRIVER);
/* init printf */
init_printf(NULL,sendchar_pf);
/* init printf */
init_printf(NULL, sendchar_pf);
#ifdef MIDI_ENABLE
setup_midi();
setup_midi();
#endif
#ifdef SERIAL_LINK_ENABLE
init_serial_link();
init_serial_link();
#endif
#ifdef VISUALIZER_ENABLE
visualizer_init();
visualizer_init();
#endif
host_driver_t *driver = NULL;
host_driver_t* driver = NULL;
/* Wait until the USB or serial link is active */
while (true) {
/* Wait until the USB or serial link is active */
while (true) {
#if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
if(USB_DRIVER.state == USB_ACTIVE) {
driver = &chibios_driver;
break;
}
if (USB_DRIVER.state == USB_ACTIVE) {
driver = &chibios_driver;
break;
}
#else
driver = &chibios_driver;
break;
driver = &chibios_driver;
break;
#endif
#ifdef SERIAL_LINK_ENABLE
if(is_serial_link_connected()) {
driver = get_serial_link_driver();
break;
}
serial_link_update();
#endif
wait_ms(50);
}
/* Do need to wait here!
* Otherwise the next print might start a transfer on console EP
* before the USB is completely ready, which sometimes causes
* HardFaults.
*/
wait_ms(50);
print("USB configured.\n");
/* init TMK modules */
keyboard_init();
host_set_driver(driver);
#ifdef SLEEP_LED_ENABLE
sleep_led_init();
#endif
print("Keyboard start.\n");
/* Main loop */
while(true) {
#if !defined(NO_USB_STARTUP_CHECK)
if(USB_DRIVER.state == USB_SUSPENDED) {
print("[s]");
#ifdef VISUALIZER_ENABLE
visualizer_suspend();
#endif
while(USB_DRIVER.state == USB_SUSPENDED) {
/* Do this in the suspended state */
#ifdef SERIAL_LINK_ENABLE
if (is_serial_link_connected()) {
driver = get_serial_link_driver();
break;
}
serial_link_update();
#endif
suspend_power_down(); // on AVR this deep sleeps for 15ms
/* Remote wakeup */
if(suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
}
}
/* Woken up */
// variables has been already cleared by the wakeup hook
send_keyboard_report();
#ifdef MOUSEKEY_ENABLE
mousekey_send();
#endif /* MOUSEKEY_ENABLE */
#ifdef VISUALIZER_ENABLE
visualizer_resume();
#endif
wait_ms(50);
}
/* Do need to wait here!
* Otherwise the next print might start a transfer on console EP
* before the USB is completely ready, which sometimes causes
* HardFaults.
*/
wait_ms(50);
print("USB configured.\n");
/* init TMK modules */
keyboard_init();
host_set_driver(driver);
#ifdef SLEEP_LED_ENABLE
sleep_led_init();
#endif
keyboard_task();
print("Keyboard start.\n");
/* Main loop */
while (true) {
#if !defined(NO_USB_STARTUP_CHECK)
if (USB_DRIVER.state == USB_SUSPENDED) {
print("[s]");
# ifdef VISUALIZER_ENABLE
visualizer_suspend();
# endif
while (USB_DRIVER.state == USB_SUSPENDED) {
/* Do this in the suspended state */
# ifdef SERIAL_LINK_ENABLE
serial_link_update();
# endif
suspend_power_down(); // on AVR this deep sleeps for 15ms
/* Remote wakeup */
if (suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
}
}
/* Woken up */
// variables has been already cleared by the wakeup hook
send_keyboard_report();
# ifdef MOUSEKEY_ENABLE
mousekey_send();
# endif /* MOUSEKEY_ENABLE */
# ifdef VISUALIZER_ENABLE
visualizer_resume();
# endif
}
#endif
keyboard_task();
#ifdef CONSOLE_ENABLE
console_task();
console_task();
#endif
#ifdef VIRTSER_ENABLE
virtser_task();
virtser_task();
#endif
#ifdef RAW_ENABLE
raw_hid_task();
raw_hid_task();
#endif
}
}
}

View file

@ -41,93 +41,62 @@
/*
* Current Line Coding.
*/
static cdc_linecoding_t linecoding = {
{0x00, 0x96, 0x00, 0x00}, /* 38400. */
LC_STOP_1, LC_PARITY_NONE, 8
};
static cdc_linecoding_t linecoding = {{0x00, 0x96, 0x00, 0x00}, /* 38400. */
LC_STOP_1,
LC_PARITY_NONE,
8};
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
static bool qmkusb_start_receive(QMKUSBDriver *qmkusbp) {
uint8_t *buf;
uint8_t *buf;
/* If the USB driver is not in the appropriate state then transactions
must not be started.*/
if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) ||
(qmkusbp->state != QMKUSB_READY)) {
return true;
}
/* If the USB driver is not in the appropriate state then transactions
must not be started.*/
if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) || (qmkusbp->state != QMKUSB_READY)) {
return true;
}
/* Checking if there is already a transaction ongoing on the endpoint.*/
if (usbGetReceiveStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
return true;
}
/* Checking if there is already a transaction ongoing on the endpoint.*/
if (usbGetReceiveStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
return true;
}
/* Checking if there is a buffer ready for incoming data.*/
buf = ibqGetEmptyBufferI(&qmkusbp->ibqueue);
if (buf == NULL) {
return true;
}
/* Checking if there is a buffer ready for incoming data.*/
buf = ibqGetEmptyBufferI(&qmkusbp->ibqueue);
if (buf == NULL) {
return true;
}
/* Buffer found, starting a new transaction.*/
usbStartReceiveI(qmkusbp->config->usbp, qmkusbp->config->bulk_out,
buf, qmkusbp->ibqueue.bsize - sizeof(size_t));
/* Buffer found, starting a new transaction.*/
usbStartReceiveI(qmkusbp->config->usbp, qmkusbp->config->bulk_out, buf, qmkusbp->ibqueue.bsize - sizeof(size_t));
return false;
return false;
}
/*
* Interface implementation.
*/
static size_t _write(void *ip, const uint8_t *bp, size_t n) {
static size_t _write(void *ip, const uint8_t *bp, size_t n) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, TIME_INFINITE); }
return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp,
n, TIME_INFINITE);
}
static size_t _read(void *ip, uint8_t *bp, size_t n) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, TIME_INFINITE); }
static size_t _read(void *ip, uint8_t *bp, size_t n) {
static msg_t _put(void *ip, uint8_t b) { return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, TIME_INFINITE); }
return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp,
n, TIME_INFINITE);
}
static msg_t _get(void *ip) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, TIME_INFINITE); }
static msg_t _put(void *ip, uint8_t b) {
static msg_t _putt(void *ip, uint8_t b, systime_t timeout) { return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, timeout); }
return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, TIME_INFINITE);
}
static msg_t _gett(void *ip, systime_t timeout) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, timeout); }
static msg_t _get(void *ip) {
static size_t _writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, timeout); }
return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, TIME_INFINITE);
}
static size_t _readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, timeout); }
static msg_t _putt(void *ip, uint8_t b, systime_t timeout) {
return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, timeout);
}
static msg_t _gett(void *ip, systime_t timeout) {
return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, timeout);
}
static size_t _writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) {
return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, timeout);
}
static size_t _readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) {
return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, timeout);
}
static const struct QMKUSBDriverVMT vmt = {
_write, _read, _put, _get,
_putt, _gett, _writet, _readt
};
static const struct QMKUSBDriverVMT vmt = {_write, _read, _put, _get, _putt, _gett, _writet, _readt};
/**
* @brief Notification of empty buffer released into the input buffers queue.
@ -135,8 +104,8 @@ static const struct QMKUSBDriverVMT vmt = {
* @param[in] bqp the buffers queue pointer.
*/
static void ibnotify(io_buffers_queue_t *bqp) {
QMKUSBDriver *qmkusbp = bqGetLinkX(bqp);
(void) qmkusb_start_receive(qmkusbp);
QMKUSBDriver *qmkusbp = bqGetLinkX(bqp);
(void)qmkusb_start_receive(qmkusbp);
}
/**
@ -145,25 +114,24 @@ static void ibnotify(io_buffers_queue_t *bqp) {
* @param[in] bqp the buffers queue pointer.
*/
static void obnotify(io_buffers_queue_t *bqp) {
size_t n;
QMKUSBDriver *qmkusbp = bqGetLinkX(bqp);
size_t n;
QMKUSBDriver *qmkusbp = bqGetLinkX(bqp);
/* If the USB driver is not in the appropriate state then transactions
must not be started.*/
if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) ||
(qmkusbp->state != QMKUSB_READY)) {
return;
}
/* Checking if there is already a transaction ongoing on the endpoint.*/
if (!usbGetTransmitStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
/* Trying to get a full buffer.*/
uint8_t *buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
if (buf != NULL) {
/* Buffer found, starting a new transaction.*/
usbStartTransmitI(qmkusbp->config->usbp, qmkusbp->config->bulk_in, buf, n);
/* If the USB driver is not in the appropriate state then transactions
must not be started.*/
if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) || (qmkusbp->state != QMKUSB_READY)) {
return;
}
/* Checking if there is already a transaction ongoing on the endpoint.*/
if (!usbGetTransmitStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
/* Trying to get a full buffer.*/
uint8_t *buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
if (buf != NULL) {
/* Buffer found, starting a new transaction.*/
usbStartTransmitI(qmkusbp->config->usbp, qmkusbp->config->bulk_in, buf, n);
}
}
}
}
/*===========================================================================*/
@ -177,8 +145,7 @@ static void obnotify(io_buffers_queue_t *bqp) {
*
* @init
*/
void qmkusbInit(void) {
}
void qmkusbInit(void) {}
/**
* @brief Initializes a generic full duplex driver object.
@ -190,17 +157,12 @@ void qmkusbInit(void) {
* @init
*/
void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config) {
qmkusbp->vmt = &vmt;
osalEventObjectInit(&qmkusbp->event);
qmkusbp->state = QMKUSB_STOP;
// Note that the config uses the USB direction naming
ibqObjectInit(&qmkusbp->ibqueue, true, config->ob,
config->out_size, config->out_buffers,
ibnotify, qmkusbp);
obqObjectInit(&qmkusbp->obqueue, true, config->ib,
config->in_size, config->in_buffers,
obnotify, qmkusbp);
qmkusbp->vmt = &vmt;
osalEventObjectInit(&qmkusbp->event);
qmkusbp->state = QMKUSB_STOP;
// Note that the config uses the USB direction naming
ibqObjectInit(&qmkusbp->ibqueue, true, config->ob, config->out_size, config->out_buffers, ibnotify, qmkusbp);
obqObjectInit(&qmkusbp->obqueue, true, config->ib, config->in_size, config->in_buffers, obnotify, qmkusbp);
}
/**
@ -212,21 +174,20 @@ void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config) {
* @api
*/
void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config) {
USBDriver *usbp = config->usbp;
USBDriver *usbp = config->usbp;
osalDbgCheck(qmkusbp != NULL);
osalDbgCheck(qmkusbp != NULL);
osalSysLock();
osalDbgAssert((qmkusbp->state == QMKUSB_STOP) || (qmkusbp->state == QMKUSB_READY),
"invalid state");
usbp->in_params[config->bulk_in - 1U] = qmkusbp;
usbp->out_params[config->bulk_out - 1U] = qmkusbp;
if (config->int_in > 0U) {
usbp->in_params[config->int_in - 1U] = qmkusbp;
}
qmkusbp->config = config;
qmkusbp->state = QMKUSB_READY;
osalSysUnlock();
osalSysLock();
osalDbgAssert((qmkusbp->state == QMKUSB_STOP) || (qmkusbp->state == QMKUSB_READY), "invalid state");
usbp->in_params[config->bulk_in - 1U] = qmkusbp;
usbp->out_params[config->bulk_out - 1U] = qmkusbp;
if (config->int_in > 0U) {
usbp->in_params[config->int_in - 1U] = qmkusbp;
}
qmkusbp->config = config;
qmkusbp->state = QMKUSB_READY;
osalSysUnlock();
}
/**
@ -239,31 +200,30 @@ void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config) {
* @api
*/
void qmkusbStop(QMKUSBDriver *qmkusbp) {
USBDriver *usbp = qmkusbp->config->usbp;
USBDriver *usbp = qmkusbp->config->usbp;
osalDbgCheck(qmkusbp != NULL);
osalDbgCheck(qmkusbp != NULL);
osalSysLock();
osalSysLock();
osalDbgAssert((qmkusbp->state == QMKUSB_STOP) || (qmkusbp->state == QMKUSB_READY),
"invalid state");
osalDbgAssert((qmkusbp->state == QMKUSB_STOP) || (qmkusbp->state == QMKUSB_READY), "invalid state");
/* Driver in stopped state.*/
usbp->in_params[qmkusbp->config->bulk_in - 1U] = NULL;
usbp->out_params[qmkusbp->config->bulk_out - 1U] = NULL;
if (qmkusbp->config->int_in > 0U) {
usbp->in_params[qmkusbp->config->int_in - 1U] = NULL;
}
qmkusbp->config = NULL;
qmkusbp->state = QMKUSB_STOP;
/* Driver in stopped state.*/
usbp->in_params[qmkusbp->config->bulk_in - 1U] = NULL;
usbp->out_params[qmkusbp->config->bulk_out - 1U] = NULL;
if (qmkusbp->config->int_in > 0U) {
usbp->in_params[qmkusbp->config->int_in - 1U] = NULL;
}
qmkusbp->config = NULL;
qmkusbp->state = QMKUSB_STOP;
/* Enforces a disconnection.*/
chnAddFlagsI(qmkusbp, CHN_DISCONNECTED);
ibqResetI(&qmkusbp->ibqueue);
obqResetI(&qmkusbp->obqueue);
osalOsRescheduleS();
/* Enforces a disconnection.*/
chnAddFlagsI(qmkusbp, CHN_DISCONNECTED);
ibqResetI(&qmkusbp->ibqueue);
obqResetI(&qmkusbp->obqueue);
osalOsRescheduleS();
osalSysUnlock();
osalSysUnlock();
}
/**
@ -279,10 +239,9 @@ void qmkusbStop(QMKUSBDriver *qmkusbp) {
* @iclass
*/
void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp) {
chnAddFlagsI(qmkusbp, CHN_DISCONNECTED);
bqSuspendI(&qmkusbp->ibqueue);
bqSuspendI(&qmkusbp->obqueue);
chnAddFlagsI(qmkusbp, CHN_DISCONNECTED);
bqSuspendI(&qmkusbp->ibqueue);
bqSuspendI(&qmkusbp->obqueue);
}
/**
@ -298,10 +257,9 @@ void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp) {
* @iclass
*/
void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp) {
chnAddFlagsI(qmkusbp, CHN_CONNECTED);
bqResumeX(&qmkusbp->ibqueue);
bqResumeX(&qmkusbp->obqueue);
chnAddFlagsI(qmkusbp, CHN_CONNECTED);
bqResumeX(&qmkusbp->ibqueue);
bqResumeX(&qmkusbp->obqueue);
}
/**
@ -312,13 +270,12 @@ void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp) {
* @iclass
*/
void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp) {
ibqResetI(&qmkusbp->ibqueue);
bqResumeX(&qmkusbp->ibqueue);
obqResetI(&qmkusbp->obqueue);
bqResumeX(&qmkusbp->obqueue);
chnAddFlagsI(qmkusbp, CHN_CONNECTED);
(void) qmkusb_start_receive(qmkusbp);
ibqResetI(&qmkusbp->ibqueue);
bqResumeX(&qmkusbp->ibqueue);
obqResetI(&qmkusbp->obqueue);
bqResumeX(&qmkusbp->obqueue);
chnAddFlagsI(qmkusbp, CHN_CONNECTED);
(void)qmkusb_start_receive(qmkusbp);
}
/**
@ -337,24 +294,23 @@ void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp) {
* @retval false Message not handled.
*/
bool qmkusbRequestsHook(USBDriver *usbp) {
if ((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) {
switch (usbp->setup[1]) {
case CDC_GET_LINE_CODING:
usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL);
return true;
case CDC_SET_LINE_CODING:
usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL);
return true;
case CDC_SET_CONTROL_LINE_STATE:
/* Nothing to do, there are no control lines.*/
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
default:
return false;
if ((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) {
switch (usbp->setup[1]) {
case CDC_GET_LINE_CODING:
usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL);
return true;
case CDC_SET_LINE_CODING:
usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL);
return true;
case CDC_SET_CONTROL_LINE_STATE:
/* Nothing to do, there are no control lines.*/
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
default:
return false;
}
}
}
return false;
return false;
}
/**
@ -367,36 +323,34 @@ bool qmkusbRequestsHook(USBDriver *usbp) {
* @iclass
*/
void qmkusbSOFHookI(QMKUSBDriver *qmkusbp) {
/* If the USB driver is not in the appropriate state then transactions
must not be started.*/
if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) ||
(qmkusbp->state != QMKUSB_READY)) {
return;
}
/* If there is already a transaction ongoing then another one cannot be
started.*/
if (usbGetTransmitStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
return;
}
/* Checking if there only a buffer partially filled, if so then it is
enforced in the queue and transmitted.*/
if (obqTryFlushI(&qmkusbp->obqueue)) {
size_t n;
uint8_t *buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
/* For fixed size drivers, fill the end with zeros */
if (qmkusbp->config->fixed_size) {
memset(buf + n, 0, qmkusbp->config->in_size - n);
n = qmkusbp->config->in_size;
/* If the USB driver is not in the appropriate state then transactions
must not be started.*/
if ((usbGetDriverStateI(qmkusbp->config->usbp) != USB_ACTIVE) || (qmkusbp->state != QMKUSB_READY)) {
return;
}
osalDbgAssert(buf != NULL, "queue is empty");
/* If there is already a transaction ongoing then another one cannot be
started.*/
if (usbGetTransmitStatusI(qmkusbp->config->usbp, qmkusbp->config->bulk_in)) {
return;
}
usbStartTransmitI(qmkusbp->config->usbp, qmkusbp->config->bulk_in, buf, n);
}
/* Checking if there only a buffer partially filled, if so then it is
enforced in the queue and transmitted.*/
if (obqTryFlushI(&qmkusbp->obqueue)) {
size_t n;
uint8_t *buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
/* For fixed size drivers, fill the end with zeros */
if (qmkusbp->config->fixed_size) {
memset(buf + n, 0, qmkusbp->config->in_size - n);
n = qmkusbp->config->in_size;
}
osalDbgAssert(buf != NULL, "queue is empty");
usbStartTransmitI(qmkusbp->config->usbp, qmkusbp->config->bulk_in, buf, n);
}
}
/**
@ -408,49 +362,45 @@ void qmkusbSOFHookI(QMKUSBDriver *qmkusbp) {
* @param[in] ep IN endpoint number
*/
void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep) {
uint8_t *buf;
size_t n;
QMKUSBDriver *qmkusbp = usbp->in_params[ep - 1U];
uint8_t * buf;
size_t n;
QMKUSBDriver *qmkusbp = usbp->in_params[ep - 1U];
if (qmkusbp == NULL) {
return;
}
osalSysLockFromISR();
/* Signaling that space is available in the output queue.*/
chnAddFlagsI(qmkusbp, CHN_OUTPUT_EMPTY);
/* Freeing the buffer just transmitted, if it was not a zero size packet.*/
if (usbp->epc[ep]->in_state->txsize > 0U) {
obqReleaseEmptyBufferI(&qmkusbp->obqueue);
}
/* Checking if there is a buffer ready for transmission.*/
buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
if (buf != NULL) {
/* The endpoint cannot be busy, we are in the context of the callback,
so it is safe to transmit without a check.*/
usbStartTransmitI(usbp, ep, buf, n);
}
else if ((usbp->epc[ep]->in_state->txsize > 0U) &&
((usbp->epc[ep]->in_state->txsize &
((size_t)usbp->epc[ep]->in_maxsize - 1U)) == 0U)) {
/* Transmit zero sized packet in case the last one has maximum allowed
size. Otherwise the recipient may expect more data coming soon and
not return buffered data to app. See section 5.8.3 Bulk Transfer
Packet Size Constraints of the USB Specification document.*/
if (!qmkusbp->config->fixed_size) {
usbStartTransmitI(usbp, ep, usbp->setup, 0);
if (qmkusbp == NULL) {
return;
}
}
else {
/* Nothing to transmit.*/
}
osalSysLockFromISR();
osalSysUnlockFromISR();
/* Signaling that space is available in the output queue.*/
chnAddFlagsI(qmkusbp, CHN_OUTPUT_EMPTY);
/* Freeing the buffer just transmitted, if it was not a zero size packet.*/
if (usbp->epc[ep]->in_state->txsize > 0U) {
obqReleaseEmptyBufferI(&qmkusbp->obqueue);
}
/* Checking if there is a buffer ready for transmission.*/
buf = obqGetFullBufferI(&qmkusbp->obqueue, &n);
if (buf != NULL) {
/* The endpoint cannot be busy, we are in the context of the callback,
so it is safe to transmit without a check.*/
usbStartTransmitI(usbp, ep, buf, n);
} else if ((usbp->epc[ep]->in_state->txsize > 0U) && ((usbp->epc[ep]->in_state->txsize & ((size_t)usbp->epc[ep]->in_maxsize - 1U)) == 0U)) {
/* Transmit zero sized packet in case the last one has maximum allowed
size. Otherwise the recipient may expect more data coming soon and
not return buffered data to app. See section 5.8.3 Bulk Transfer
Packet Size Constraints of the USB Specification document.*/
if (!qmkusbp->config->fixed_size) {
usbStartTransmitI(usbp, ep, usbp->setup, 0);
}
} else {
/* Nothing to transmit.*/
}
osalSysUnlockFromISR();
}
/**
@ -462,27 +412,25 @@ void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep) {
* @param[in] ep OUT endpoint number
*/
void qmkusbDataReceived(USBDriver *usbp, usbep_t ep) {
QMKUSBDriver *qmkusbp = usbp->out_params[ep - 1U];
if (qmkusbp == NULL) {
return;
}
QMKUSBDriver *qmkusbp = usbp->out_params[ep - 1U];
if (qmkusbp == NULL) {
return;
}
osalSysLockFromISR();
osalSysLockFromISR();
/* Signaling that data is available in the input queue.*/
chnAddFlagsI(qmkusbp, CHN_INPUT_AVAILABLE);
/* Signaling that data is available in the input queue.*/
chnAddFlagsI(qmkusbp, CHN_INPUT_AVAILABLE);
/* Posting the filled buffer in the queue.*/
ibqPostFullBufferI(&qmkusbp->ibqueue,
usbGetReceiveTransactionSizeX(qmkusbp->config->usbp,
qmkusbp->config->bulk_out));
/* Posting the filled buffer in the queue.*/
ibqPostFullBufferI(&qmkusbp->ibqueue, usbGetReceiveTransactionSizeX(qmkusbp->config->usbp, qmkusbp->config->bulk_out));
/* The endpoint cannot be busy, we are in the context of the callback,
so a packet is in the buffer for sure. Trying to get a free buffer
for the next transaction.*/
(void) qmkusb_start_receive(qmkusbp);
/* The endpoint cannot be busy, we are in the context of the callback,
so a packet is in the buffer for sure. Trying to get a free buffer
for the next transaction.*/
(void)qmkusb_start_receive(qmkusbp);
osalSysUnlockFromISR();
osalSysUnlockFromISR();
}
/**
@ -494,9 +442,8 @@ void qmkusbDataReceived(USBDriver *usbp, usbep_t ep) {
* @param[in] ep endpoint number
*/
void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep) {
(void)usbp;
(void)ep;
(void)usbp;
(void)ep;
}
/** @} */

View file

@ -23,9 +23,9 @@
*/
#ifndef USB_DRIVER_H
#define USB_DRIVER_H
# define USB_DRIVER_H
#include "hal_usb_cdc.h"
# include "hal_usb_cdc.h"
/*===========================================================================*/
/* Driver constants. */
@ -35,9 +35,9 @@
/* Derived constants and error checks. */
/*===========================================================================*/
#if HAL_USE_USB == FALSE
#error "The USB Driver requires HAL_USE_USB"
#endif
# if HAL_USE_USB == FALSE
# error "The USB Driver requires HAL_USE_USB"
# endif
/*===========================================================================*/
/* Driver data structures and types. */
@ -47,9 +47,9 @@
* @brief Driver state machine possible states.
*/
typedef enum {
QMKUSB_UNINIT = 0, /**< Not initialized. */
QMKUSB_STOP = 1, /**< Stopped. */
QMKUSB_READY = 2 /**< Ready. */
QMKUSB_UNINIT = 0, /**< Not initialized. */
QMKUSB_STOP = 1, /**< Stopped. */
QMKUSB_READY = 2 /**< Ready. */
} qmkusbstate_t;
/**
@ -63,72 +63,70 @@ typedef struct QMKUSBDriver QMKUSBDriver;
* in order to configure and start the driver operations.
*/
typedef struct {
/**
* @brief USB driver to use.
*/
USBDriver *usbp;
/**
* @brief Bulk IN endpoint used for outgoing data transfer.
*/
usbep_t bulk_in;
/**
* @brief Bulk OUT endpoint used for incoming data transfer.
*/
usbep_t bulk_out;
/**
* @brief Interrupt IN endpoint used for notifications.
* @note If set to zero then the INT endpoint is assumed to be not
* present, USB descriptors must be changed accordingly.
*/
usbep_t int_in;
/**
* @brief USB driver to use.
*/
USBDriver *usbp;
/**
* @brief Bulk IN endpoint used for outgoing data transfer.
*/
usbep_t bulk_in;
/**
* @brief Bulk OUT endpoint used for incoming data transfer.
*/
usbep_t bulk_out;
/**
* @brief Interrupt IN endpoint used for notifications.
* @note If set to zero then the INT endpoint is assumed to be not
* present, USB descriptors must be changed accordingly.
*/
usbep_t int_in;
/**
* @brief The number of buffers in the queues
*/
size_t in_buffers;
size_t out_buffers;
/**
* @brief The number of buffers in the queues
*/
size_t in_buffers;
size_t out_buffers;
/**
* @brief The size of each buffer in the queue, typically the same as the endpoint size
*/
size_t in_size;
size_t out_size;
/**
* @brief The size of each buffer in the queue, typically the same as the endpoint size
*/
size_t in_size;
size_t out_size;
/**
* @brief Always send full buffers in_size (the rest is filled with zeroes)
*/
bool fixed_size;
/**
* @brief Always send full buffers in_size (the rest is filled with zeroes)
*/
bool fixed_size;
/* Input buffer
* @note needs to be initialized with a memory buffer of the right size
*/
uint8_t* ib;
/* Output buffer
* @note needs to be initialized with a memory buffer of the right size
*/
uint8_t* ob;
/* Input buffer
* @note needs to be initialized with a memory buffer of the right size
*/
uint8_t *ib;
/* Output buffer
* @note needs to be initialized with a memory buffer of the right size
*/
uint8_t *ob;
} QMKUSBConfig;
/**
* @brief @p SerialDriver specific data.
*/
#define _qmk_usb_driver_data \
_base_asynchronous_channel_data \
/* Driver state.*/ \
qmkusbstate_t state; \
/* Input buffers queue.*/ \
input_buffers_queue_t ibqueue; \
/* Output queue.*/ \
output_buffers_queue_t obqueue; \
/* End of the mandatory fields.*/ \
/* Current configuration data.*/ \
const QMKUSBConfig *config;
# define _qmk_usb_driver_data \
_base_asynchronous_channel_data /* Driver state.*/ \
qmkusbstate_t state; \
/* Input buffers queue.*/ \
input_buffers_queue_t ibqueue; \
/* Output queue.*/ \
output_buffers_queue_t obqueue; \
/* End of the mandatory fields.*/ \
/* Current configuration data.*/ \
const QMKUSBConfig *config;
/**
* @brief @p SerialUSBDriver specific methods.
*/
#define _qmk_usb_driver_methods \
_base_asynchronous_channel_methods
# define _qmk_usb_driver_methods _base_asynchronous_channel_methods
/**
* @extends BaseAsynchronousChannelVMT
@ -136,7 +134,7 @@ typedef struct {
* @brief @p SerialDriver virtual methods table.
*/
struct QMKUSBDriverVMT {
_qmk_usb_driver_methods
_qmk_usb_driver_methods
};
/**
@ -147,9 +145,9 @@ struct QMKUSBDriverVMT {
* I/O queues.
*/
struct QMKUSBDriver {
/** @brief Virtual Methods Table.*/
const struct QMKUSBDriverVMT *vmt;
_qmk_usb_driver_data
/** @brief Virtual Methods Table.*/
const struct QMKUSBDriverVMT *vmt;
_qmk_usb_driver_data
};
/*===========================================================================*/
@ -160,24 +158,24 @@ struct QMKUSBDriver {
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
# ifdef __cplusplus
extern "C" {
#endif
void qmkusbInit(void);
void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig * config);
void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
void qmkusbStop(QMKUSBDriver *qmkusbp);
void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp);
void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp);
void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp);
bool qmkusbRequestsHook(USBDriver *usbp);
void qmkusbSOFHookI(QMKUSBDriver *qmkusbp);
void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep);
void qmkusbDataReceived(USBDriver *usbp, usbep_t ep);
void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep);
#ifdef __cplusplus
# endif
void qmkusbInit(void);
void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
void qmkusbStop(QMKUSBDriver *qmkusbp);
void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp);
void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp);
void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp);
bool qmkusbRequestsHook(USBDriver *usbp);
void qmkusbSOFHookI(QMKUSBDriver *qmkusbp);
void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep);
void qmkusbDataReceived(USBDriver *usbp, usbep_t ep);
void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep);
# ifdef __cplusplus
}
#endif
# endif
#endif /* USB_DRIVER_H */

File diff suppressed because it is too large Load diff

View file

@ -15,7 +15,6 @@
* GPL v2 or later.
*/
#ifndef _USB_MAIN_H_
#define _USB_MAIN_H_
@ -82,9 +81,9 @@ void shared_in_cb(USBDriver *usbp, usbep_t ep);
/* extra report structure */
typedef struct {
uint8_t report_id;
uint16_t usage;
} __attribute__ ((packed)) report_extra_t;
uint8_t report_id;
uint16_t usage;
} __attribute__((packed)) report_extra_t;
#endif /* EXTRAKEY_ENABLE */
/* --------------

View file

@ -7,24 +7,21 @@ Copyright 2010,2011,2012,2013 Jun WAKO <wakojun@gmail.com>
#include "ring_buffer.h"
#include "ibm4704.h"
#define WAIT(stat, us, err) do { \
if (!wait_##stat(us)) { \
ibm4704_error = err; \
goto ERROR; \
} \
} while (0)
#define WAIT(stat, us, err) \
do { \
if (!wait_##stat(us)) { \
ibm4704_error = err; \
goto ERROR; \
} \
} while (0)
uint8_t ibm4704_error = 0;
void ibm4704_init(void)
{
void ibm4704_init(void) {
inhibit(); // keep keyboard from sending
IBM4704_INT_INIT();
IBM4704_INT_ON();
idle(); // allow keyboard sending
idle(); // allow keyboard sending
}
/*
@ -46,9 +43,8 @@ Timing: After Request keyboard pull up Data and down Clock line to low for s
Host writes a bit while Clock is hi and Keyboard reads while low.
Stop bit: Host releases or pulls up Data line to hi after 9th clock and waits for keyboard pull down the line to lo.
*/
uint8_t ibm4704_send(uint8_t data)
{
bool parity = true; // odd parity
uint8_t ibm4704_send(uint8_t data) {
bool parity = true; // odd parity
ibm4704_error = 0;
IBM4704_INT_OFF();
@ -62,19 +58,23 @@ uint8_t ibm4704_send(uint8_t data)
/* Data bit */
for (uint8_t i = 0; i < 8; i++) {
WAIT(clock_hi, 100, 0x40+i);
if (data&(1<<i)) {
WAIT(clock_hi, 100, 0x40 + i);
if (data & (1 << i)) {
parity = !parity;
data_hi();
} else {
data_lo();
}
WAIT(clock_lo, 100, 0x48+i);
WAIT(clock_lo, 100, 0x48 + i);
}
/* Parity bit */
WAIT(clock_hi, 100, 0x34);
if (parity) { data_hi(); } else { data_lo(); }
if (parity) {
data_hi();
} else {
data_lo();
}
WAIT(clock_lo, 100, 0x35);
/* Stop bit */
@ -97,16 +97,14 @@ ERROR:
}
/* wait forever to receive data */
uint8_t ibm4704_recv_response(void)
{
uint8_t ibm4704_recv_response(void) {
while (!rbuf_has_data()) {
_delay_ms(1);
}
return rbuf_dequeue();
}
uint8_t ibm4704_recv(void)
{
uint8_t ibm4704_recv(void) {
if (rbuf_has_data()) {
return rbuf_dequeue();
} else {
@ -121,7 +119,7 @@ Data bits are LSB first and Parity is odd. Clock has around 60us high and 30us l
____ __ __ __ __ __ __ __ __ __ _______
Clock \_____/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
____ ____ ____ ____ ____ ____ ____ ____ ____ ____
____ ____ ____ ____ ____ ____ ____ ____ ____ ____
Data ____/ X____X____X____X____X____X____X____X____X____X________
Start 0 1 2 3 4 5 6 7 P Stop
@ -130,11 +128,8 @@ Inhibit: Pull Data line down to inhibit keyboard to send.
Timing: Host reads bit while Clock is hi.(rising edge)
Stop bit: Keyboard pulls down Data line to lo after 9th clock.
*/
ISR(IBM4704_INT_VECT)
{
static enum {
BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY, STOP
} state = BIT0;
ISR(IBM4704_INT_VECT) {
static enum { BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY, STOP } state = BIT0;
// LSB first
static uint8_t data = 0;
// Odd parity
@ -161,8 +156,7 @@ ISR(IBM4704_INT_VECT)
if (data_in()) {
parity = !parity;
}
if (!parity)
goto ERROR;
if (!parity) goto ERROR;
break;
case STOP:
// Data:Low
@ -178,11 +172,11 @@ ISR(IBM4704_INT_VECT)
goto RETURN;
ERROR:
ibm4704_error = state;
while (ibm4704_send(0xFE)) _delay_ms(1); // resend
while (ibm4704_send(0xFE)) _delay_ms(1); // resend
xprintf("R:%02X%02X\n", state, data);
DONE:
state = BIT0;
data = 0;
state = BIT0;
data = 0;
parity = false;
RETURN:
return;

View file

@ -4,105 +4,100 @@ Copyright 2014 Jun WAKO <wakojun@gmail.com>
#ifndef IBM4704_H
#define IBM4704_H
#define IBM4704_ERR_NONE 0
#define IBM4704_ERR_PARITY 0x70
#define IBM4704_ERR_NONE 0
#define IBM4704_ERR_PARITY 0x70
void ibm4704_init(void);
void ibm4704_init(void);
uint8_t ibm4704_send(uint8_t data);
uint8_t ibm4704_recv_response(void);
uint8_t ibm4704_recv(void);
/* Check pin configuration */
#if !(defined(IBM4704_CLOCK_PORT) && \
defined(IBM4704_CLOCK_PIN) && \
defined(IBM4704_CLOCK_DDR) && \
defined(IBM4704_CLOCK_BIT))
# error "ibm4704 clock pin configuration is required in config.h"
#if !(defined(IBM4704_CLOCK_PORT) && defined(IBM4704_CLOCK_PIN) && defined(IBM4704_CLOCK_DDR) && defined(IBM4704_CLOCK_BIT))
# error "ibm4704 clock pin configuration is required in config.h"
#endif
#if !(defined(IBM4704_DATA_PORT) && \
defined(IBM4704_DATA_PIN) && \
defined(IBM4704_DATA_DDR) && \
defined(IBM4704_DATA_BIT))
# error "ibm4704 data pin configuration is required in config.h"
#if !(defined(IBM4704_DATA_PORT) && defined(IBM4704_DATA_PIN) && defined(IBM4704_DATA_DDR) && defined(IBM4704_DATA_BIT))
# error "ibm4704 data pin configuration is required in config.h"
#endif
/*--------------------------------------------------------------------
* static functions
*------------------------------------------------------------------*/
static inline void clock_lo(void)
{
IBM4704_CLOCK_PORT &= ~(1<<IBM4704_CLOCK_BIT);
IBM4704_CLOCK_DDR |= (1<<IBM4704_CLOCK_BIT);
static inline void clock_lo(void) {
IBM4704_CLOCK_PORT &= ~(1 << IBM4704_CLOCK_BIT);
IBM4704_CLOCK_DDR |= (1 << IBM4704_CLOCK_BIT);
}
static inline void clock_hi(void)
{
static inline void clock_hi(void) {
/* input with pull up */
IBM4704_CLOCK_DDR &= ~(1<<IBM4704_CLOCK_BIT);
IBM4704_CLOCK_PORT |= (1<<IBM4704_CLOCK_BIT);
IBM4704_CLOCK_DDR &= ~(1 << IBM4704_CLOCK_BIT);
IBM4704_CLOCK_PORT |= (1 << IBM4704_CLOCK_BIT);
}
static inline bool clock_in(void)
{
IBM4704_CLOCK_DDR &= ~(1<<IBM4704_CLOCK_BIT);
IBM4704_CLOCK_PORT |= (1<<IBM4704_CLOCK_BIT);
static inline bool clock_in(void) {
IBM4704_CLOCK_DDR &= ~(1 << IBM4704_CLOCK_BIT);
IBM4704_CLOCK_PORT |= (1 << IBM4704_CLOCK_BIT);
_delay_us(1);
return IBM4704_CLOCK_PIN&(1<<IBM4704_CLOCK_BIT);
return IBM4704_CLOCK_PIN & (1 << IBM4704_CLOCK_BIT);
}
static inline void data_lo(void)
{
IBM4704_DATA_PORT &= ~(1<<IBM4704_DATA_BIT);
IBM4704_DATA_DDR |= (1<<IBM4704_DATA_BIT);
static inline void data_lo(void) {
IBM4704_DATA_PORT &= ~(1 << IBM4704_DATA_BIT);
IBM4704_DATA_DDR |= (1 << IBM4704_DATA_BIT);
}
static inline void data_hi(void)
{
static inline void data_hi(void) {
/* input with pull up */
IBM4704_DATA_DDR &= ~(1<<IBM4704_DATA_BIT);
IBM4704_DATA_PORT |= (1<<IBM4704_DATA_BIT);
IBM4704_DATA_DDR &= ~(1 << IBM4704_DATA_BIT);
IBM4704_DATA_PORT |= (1 << IBM4704_DATA_BIT);
}
static inline bool data_in(void)
{
IBM4704_DATA_DDR &= ~(1<<IBM4704_DATA_BIT);
IBM4704_DATA_PORT |= (1<<IBM4704_DATA_BIT);
static inline bool data_in(void) {
IBM4704_DATA_DDR &= ~(1 << IBM4704_DATA_BIT);
IBM4704_DATA_PORT |= (1 << IBM4704_DATA_BIT);
_delay_us(1);
return IBM4704_DATA_PIN&(1<<IBM4704_DATA_BIT);
return IBM4704_DATA_PIN & (1 << IBM4704_DATA_BIT);
}
static inline uint16_t wait_clock_lo(uint16_t us)
{
while (clock_in() && us) { asm(""); _delay_us(1); us--; }
static inline uint16_t wait_clock_lo(uint16_t us) {
while (clock_in() && us) {
asm("");
_delay_us(1);
us--;
}
return us;
}
static inline uint16_t wait_clock_hi(uint16_t us)
{
while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
static inline uint16_t wait_clock_hi(uint16_t us) {
while (!clock_in() && us) {
asm("");
_delay_us(1);
us--;
}
return us;
}
static inline uint16_t wait_data_lo(uint16_t us)
{
while (data_in() && us) { asm(""); _delay_us(1); us--; }
static inline uint16_t wait_data_lo(uint16_t us) {
while (data_in() && us) {
asm("");
_delay_us(1);
us--;
}
return us;
}
static inline uint16_t wait_data_hi(uint16_t us)
{
while (!data_in() && us) { asm(""); _delay_us(1); us--; }
static inline uint16_t wait_data_hi(uint16_t us) {
while (!data_in() && us) {
asm("");
_delay_us(1);
us--;
}
return us;
}
/* idle state that device can send */
static inline void idle(void)
{
static inline void idle(void) {
clock_hi();
data_hi();
}
/* inhibit device to send
/* inhibit device to send
* keyboard checks Data line on start bit(Data:hi) and it stops sending if Data line is low.
*/
static inline void inhibit(void)
{
static inline void inhibit(void) {
clock_hi();
data_lo();
}

View file

@ -37,43 +37,39 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "iwrap.h"
#include "print.h"
/* iWRAP MUX mode utils. 3.10 HID raw mode(iWRAP_HID_Application_Note.pdf) */
#define MUX_HEADER(LINK, LENGTH) do { \
xmit(0xbf); /* SOF */ \
xmit(LINK); /* Link */ \
xmit(0x00); /* Flags */ \
xmit(LENGTH); /* Length */ \
} while (0)
#define MUX_FOOTER(LINK) xmit(LINK^0xff)
#define MUX_HEADER(LINK, LENGTH) \
do { \
xmit(0xbf); /* SOF */ \
xmit(LINK); /* Link */ \
xmit(0x00); /* Flags */ \
xmit(LENGTH); /* Length */ \
} while (0)
#define MUX_FOOTER(LINK) xmit(LINK ^ 0xff)
static uint8_t connected = 0;
//static uint8_t channel = 1;
// static uint8_t channel = 1;
/* iWRAP buffer */
#define MUX_BUF_SIZE 64
static char buf[MUX_BUF_SIZE];
static char buf[MUX_BUF_SIZE];
static uint8_t snd_pos = 0;
#define MUX_RCV_BUF_SIZE 256
static char rcv_buf[MUX_RCV_BUF_SIZE];
static char rcv_buf[MUX_RCV_BUF_SIZE];
static uint8_t rcv_head = 0;
static uint8_t rcv_tail = 0;
/* receive buffer */
static void rcv_enq(char c)
{
static void rcv_enq(char c) {
uint8_t next = (rcv_head + 1) % MUX_RCV_BUF_SIZE;
if (next != rcv_tail) {
rcv_buf[rcv_head] = c;
rcv_head = next;
rcv_head = next;
}
}
static char rcv_deq(void)
{
static char rcv_deq(void) {
char c = 0;
if (rcv_head != rcv_tail) {
c = rcv_buf[rcv_tail++];
@ -91,38 +87,33 @@ static char rcv_peek(void)
}
*/
static void rcv_clear(void)
{
rcv_tail = rcv_head = 0;
}
static void rcv_clear(void) { rcv_tail = rcv_head = 0; }
/* iWRAP response */
ISR(PCINT1_vect, ISR_BLOCK) // recv() runs away in case of ISR_NOBLOCK
ISR(PCINT1_vect, ISR_BLOCK) // recv() runs away in case of ISR_NOBLOCK
{
if ((SUART_IN_PIN & (1<<SUART_IN_BIT)))
return;
if ((SUART_IN_PIN & (1 << SUART_IN_BIT))) return;
static volatile uint8_t mux_state = 0xff;
static volatile uint8_t mux_link = 0xff;
uint8_t c = recv();
static volatile uint8_t mux_link = 0xff;
uint8_t c = recv();
switch (mux_state) {
case 0xff: // SOF
if (c == 0xbf)
mux_state--;
case 0xff: // SOF
if (c == 0xbf) mux_state--;
break;
case 0xfe: // Link
case 0xfe: // Link
mux_state--;
mux_link = c;
break;
case 0xfd: // Flags
case 0xfd: // Flags
mux_state--;
break;
case 0xfc: // Length
case 0xfc: // Length
mux_state = c;
break;
case 0x00:
mux_state = 0xff;
mux_link = 0xff;
mux_link = 0xff;
break;
default:
if (mux_state--) {
@ -132,12 +123,10 @@ ISR(PCINT1_vect, ISR_BLOCK) // recv() runs away in case of ISR_NOBLOCK
}
}
/*------------------------------------------------------------------*
* iWRAP communication
*------------------------------------------------------------------*/
void iwrap_init(void)
{
void iwrap_init(void) {
// reset iWRAP if in already MUX mode after AVR software-reset
iwrap_send("RESET");
iwrap_mux_send("RESET");
@ -147,43 +136,34 @@ void iwrap_init(void)
iwrap_check_connection();
}
void iwrap_mux_send(const char *s)
{
void iwrap_mux_send(const char *s) {
rcv_clear();
MUX_HEADER(0xff, strlen((char *)s));
iwrap_send(s);
MUX_FOOTER(0xff);
}
void iwrap_send(const char *s)
{
while (*s)
xmit(*s++);
void iwrap_send(const char *s) {
while (*s) xmit(*s++);
}
/* send buffer */
void iwrap_buf_add(uint8_t c)
{
void iwrap_buf_add(uint8_t c) {
// need space for '\0'
if (snd_pos < MUX_BUF_SIZE-1)
buf[snd_pos++] = c;
if (snd_pos < MUX_BUF_SIZE - 1) buf[snd_pos++] = c;
}
void iwrap_buf_del(void)
{
if (snd_pos)
snd_pos--;
void iwrap_buf_del(void) {
if (snd_pos) snd_pos--;
}
void iwrap_buf_send(void)
{
void iwrap_buf_send(void) {
buf[snd_pos] = '\0';
snd_pos = 0;
snd_pos = 0;
iwrap_mux_send(buf);
}
void iwrap_call(void)
{
void iwrap_call(void) {
char *p;
iwrap_mux_send("SET BT PAIR");
@ -193,7 +173,7 @@ void iwrap_call(void)
while (!strncmp(p, "SET BT PAIR", 11)) {
p += 7;
strncpy(p, "CALL", 4);
strncpy(p+22, " 11 HID\n\0", 9);
strncpy(p + 22, " 11 HID\n\0", 9);
print_S(p);
iwrap_mux_send(p);
// TODO: skip to next line
@ -224,20 +204,21 @@ void iwrap_call(void)
iwrap_check_connection();
}
void iwrap_kill(void)
{
void iwrap_kill(void) {
char c;
iwrap_mux_send("LIST");
_delay_ms(500);
while ((c = rcv_deq()) && c != '\n') ;
while ((c = rcv_deq()) && c != '\n')
;
if (strncmp(rcv_buf + rcv_tail, "LIST ", 5)) {
print("no connection to kill.\n");
return;
}
// skip 10 'space' chars
for (uint8_t i = 10; i; i--)
while ((c = rcv_deq()) && c != ' ') ;
while ((c = rcv_deq()) && c != ' ')
;
char *p = rcv_buf + rcv_tail - 5;
strncpy(p, "KILL ", 5);
@ -249,47 +230,34 @@ void iwrap_kill(void)
iwrap_check_connection();
}
void iwrap_unpair(void)
{
void iwrap_unpair(void) {
iwrap_mux_send("SET BT PAIR");
_delay_ms(500);
char *p = rcv_buf + rcv_tail;
if (!strncmp(p, "SET BT PAIR", 11)) {
strncpy(p+29, "\n\0", 2);
strncpy(p + 29, "\n\0", 2);
print_S(p);
iwrap_mux_send(p);
}
}
void iwrap_sleep(void)
{
iwrap_mux_send("SLEEP");
}
void iwrap_sleep(void) { iwrap_mux_send("SLEEP"); }
void iwrap_sniff(void)
{
}
void iwrap_sniff(void) {}
void iwrap_subrate(void)
{
}
void iwrap_subrate(void) {}
bool iwrap_failed(void)
{
bool iwrap_failed(void) {
if (strncmp(rcv_buf, "SYNTAX ERROR", 12))
return true;
else
return false;
}
uint8_t iwrap_connected(void)
{
return connected;
}
uint8_t iwrap_connected(void) { return connected; }
uint8_t iwrap_check_connection(void)
{
uint8_t iwrap_check_connection(void) {
iwrap_mux_send("LIST");
_delay_ms(100);
@ -300,44 +268,31 @@ uint8_t iwrap_check_connection(void)
return connected;
}
/*------------------------------------------------------------------*
* Host driver
*------------------------------------------------------------------*/
static uint8_t keyboard_leds(void);
static void send_keyboard(report_keyboard_t *report);
static void send_mouse(report_mouse_t *report);
static void send_system(uint16_t data);
static void send_consumer(uint16_t data);
static void send_keyboard(report_keyboard_t *report);
static void send_mouse(report_mouse_t *report);
static void send_system(uint16_t data);
static void send_consumer(uint16_t data);
static host_driver_t driver = {
keyboard_leds,
send_keyboard,
send_mouse,
send_system,
send_consumer
};
static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
host_driver_t *iwrap_driver(void)
{
return &driver;
}
host_driver_t *iwrap_driver(void) { return &driver; }
static uint8_t keyboard_leds(void) {
return 0;
}
static uint8_t keyboard_leds(void) { return 0; }
static void send_keyboard(report_keyboard_t *report)
{
static void send_keyboard(report_keyboard_t *report) {
if (!iwrap_connected() && !iwrap_check_connection()) return;
MUX_HEADER(0x01, 0x0c);
// HID raw mode header
xmit(0x9f);
xmit(0x0a); // Length
xmit(0xa1); // DATA(Input)
xmit(0x01); // Report ID
xmit(0x0a); // Length
xmit(0xa1); // DATA(Input)
xmit(0x01); // Report ID
xmit(report->mods);
xmit(0x00); // reserved byte(always 0)
xmit(0x00); // reserved byte(always 0)
xmit(report->keys[0]);
xmit(report->keys[1]);
xmit(report->keys[2]);
@ -347,16 +302,15 @@ static void send_keyboard(report_keyboard_t *report)
MUX_FOOTER(0x01);
}
static void send_mouse(report_mouse_t *report)
{
static void send_mouse(report_mouse_t *report) {
#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
if (!iwrap_connected() && !iwrap_check_connection()) return;
MUX_HEADER(0x01, 0x09);
// HID raw mode header
xmit(0x9f);
xmit(0x07); // Length
xmit(0xa1); // DATA(Input)
xmit(0x02); // Report ID
xmit(0x07); // Length
xmit(0xa1); // DATA(Input)
xmit(0x02); // Report ID
xmit(report->buttons);
xmit(report->x);
xmit(report->y);
@ -366,18 +320,14 @@ static void send_mouse(report_mouse_t *report)
#endif
}
static void send_system(uint16_t data)
{
/* not supported */
}
static void send_system(uint16_t data) { /* not supported */ }
static void send_consumer(uint16_t data)
{
static void send_consumer(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
static uint16_t last_data = 0;
uint8_t bits1 = 0;
uint8_t bits2 = 0;
uint8_t bits3 = 0;
uint8_t bits1 = 0;
uint8_t bits2 = 0;
uint8_t bits3 = 0;
if (!iwrap_connected() && !iwrap_check_connection()) return;
if (data == last_data) return;
@ -458,9 +408,9 @@ static void send_consumer(uint16_t data)
MUX_HEADER(0x01, 0x07);
xmit(0x9f);
xmit(0x05); // Length
xmit(0xa1); // DATA(Input)
xmit(0x03); // Report ID
xmit(0x05); // Length
xmit(0xa1); // DATA(Input)
xmit(0x03); // Report ID
xmit(bits1);
xmit(bits2);
xmit(bits3);

View file

@ -22,11 +22,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h>
#include "host_driver.h"
/* enable iWRAP MUX mode */
#define MUX_MODE
host_driver_t *iwrap_driver(void);
void iwrap_init(void);
@ -36,13 +34,13 @@ void iwrap_buf_send(void);
void iwrap_buf_add(uint8_t c);
void iwrap_buf_del(void);
void iwrap_call(void);
void iwrap_kill(void);
void iwrap_unpair(void);
void iwrap_sleep(void);
void iwrap_sniff(void);
void iwrap_subrate(void);
bool iwrap_failed(void);
void iwrap_call(void);
void iwrap_kill(void);
void iwrap_unpair(void);
void iwrap_sleep(void);
void iwrap_sniff(void);
void iwrap_subrate(void);
bool iwrap_failed(void);
uint8_t iwrap_connected(void);
uint8_t iwrap_check_connection(void);

View file

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <avr/interrupt.h>
#include <avr/io.h>
//#include <avr/wdt.h>
#include "wd.h" // in order to use watchdog in interrupt mode
#include "wd.h" // in order to use watchdog in interrupt mode
#include <avr/sleep.h>
#include <util/delay.h>
#include <avr/power.h>
@ -28,8 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "action.h"
#include "iwrap.h"
#ifdef PROTOCOL_VUSB
# include "vusb.h"
# include "usbdrv.h"
# include "vusb.h"
# include "usbdrv.h"
#endif
#include "uart.h"
#include "suart.h"
@ -38,13 +38,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "keycode.h"
#include "command.h"
static void sleep(uint8_t term);
static bool console(void);
static bool console_command(uint8_t c);
static void sleep(uint8_t term);
static bool console(void);
static bool console_command(uint8_t c);
static uint8_t key2asc(uint8_t key);
/*
static void set_prr(void)
{
@ -78,37 +76,32 @@ static void pullup_pins(void)
}
*/
#ifdef PROTOCOL_VUSB
static void disable_vusb(void)
{
static void disable_vusb(void) {
// disable interrupt & disconnect to prevent host from enumerating
USB_INTR_ENABLE &= ~(1 << USB_INTR_ENABLE_BIT);
usbDeviceDisconnect();
}
static void enable_vusb(void)
{
static void enable_vusb(void) {
USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
usbDeviceConnect();
}
static void init_vusb(void)
{
static void init_vusb(void) {
uint8_t i = 0;
usbInit();
disable_vusb();
/* fake USB disconnect for > 250 ms */
while(--i){
while (--i) {
_delay_ms(1);
}
enable_vusb();
}
#endif
void change_driver(host_driver_t *driver)
{
void change_driver(host_driver_t *driver) {
/*
host_clear_keyboard_report();
host_swap_keyboard_report();
@ -120,20 +113,18 @@ void change_driver(host_driver_t *driver)
host_set_driver(driver);
}
static bool sleeping = false;
static bool insomniac = false; // TODO: should be false for power saving
static bool sleeping = false;
static bool insomniac = false; // TODO: should be false for power saving
static uint16_t last_timer = 0;
int main(void)
{
int main(void) {
MCUSR = 0;
clock_prescale_set(clock_div_1);
WD_SET(WD_OFF);
// power saving: the result is worse than nothing... why?
//pullup_pins();
//set_prr();
// pullup_pins();
// set_prr();
#ifdef PROTOCOL_VUSB
disable_vusb();
@ -146,11 +137,11 @@ int main(void)
print("suart init\n");
// suart init
// PC4: Tx Output IDLE(Hi)
PORTC |= (1<<4);
DDRC |= (1<<4);
PORTC |= (1 << 4);
DDRC |= (1 << 4);
// PC5: Rx Input(pull-up)
PORTC |= (1<<5);
DDRC &= ~(1<<5);
PORTC |= (1 << 5);
DDRC &= ~(1 << 5);
// suart receive interrut(PC5/PCINT13)
PCMSK1 = 0b00100000;
PCICR = 0b00000010;
@ -164,18 +155,16 @@ int main(void)
last_timer = timer_read();
while (true) {
#ifdef PROTOCOL_VUSB
if (host_get_driver() == vusb_driver())
usbPoll();
if (host_get_driver() == vusb_driver()) usbPoll();
#endif
keyboard_task();
#ifdef PROTOCOL_VUSB
if (host_get_driver() == vusb_driver())
vusb_transfer_keyboard();
if (host_get_driver() == vusb_driver()) vusb_transfer_keyboard();
#endif
// TODO: depricated
if (matrix_is_modified() || console()) {
last_timer = timer_read();
sleeping = false;
sleeping = false;
} else if (!sleeping && timer_elapsed(last_timer) > 4000) {
sleeping = true;
iwrap_check_connection();
@ -184,7 +173,7 @@ int main(void)
// TODO: suspend.h
if (host_get_driver() == iwrap_driver()) {
if (sleeping && !insomniac) {
_delay_ms(1); // wait for UART to send
_delay_ms(1); // wait for UART to send
iwrap_sleep();
sleep(WDTO_60MS);
}
@ -192,8 +181,7 @@ int main(void)
}
}
static void sleep(uint8_t term)
{
static void sleep(uint8_t term) {
WD_SET(WD_IRQ, term);
cli();
@ -207,51 +195,46 @@ static void sleep(uint8_t term)
WD_SET(WD_OFF);
}
static bool console(void)
{
// Send to Bluetoot module WT12
static bool breaked = false;
if (!uart_available())
return false;
else {
uint8_t c;
c = uart_getchar();
uart_putchar(c);
switch (c) {
case 0x00: // BREAK signal
if (!breaked) {
print("break(? for help): ");
breaked = true;
}
break;
case '\r':
uart_putchar('\n');
iwrap_buf_send();
break;
case '\b':
iwrap_buf_del();
break;
default:
if (breaked) {
print("\n");
console_command(c);
breaked = false;
} else {
iwrap_buf_add(c);
}
break;
}
return true;
static bool console(void) {
// Send to Bluetoot module WT12
static bool breaked = false;
if (!uart_available())
return false;
else {
uint8_t c;
c = uart_getchar();
uart_putchar(c);
switch (c) {
case 0x00: // BREAK signal
if (!breaked) {
print("break(? for help): ");
breaked = true;
}
break;
case '\r':
uart_putchar('\n');
iwrap_buf_send();
break;
case '\b':
iwrap_buf_del();
break;
default:
if (breaked) {
print("\n");
console_command(c);
breaked = false;
} else {
iwrap_buf_add(c);
}
break;
}
return true;
}
}
bool command_extra(uint8_t code)
{
return console_command(key2asc(code));
}
bool command_extra(uint8_t code) { return console_command(key2asc(code)); }
static bool console_command(uint8_t c)
{
static bool console_command(uint8_t c) {
switch (c) {
case 'h':
case '?':
@ -287,11 +270,11 @@ static bool console_command(uint8_t c)
print("USB mode\n");
init_vusb();
change_driver(vusb_driver());
//iwrap_kill();
//iwrap_sleep();
// iwrap_kill();
// iwrap_sleep();
// disable suart receive interrut(PC5/PCINT13)
PCMSK1 &= ~(0b00100000);
PCICR &= ~(0b00000010);
PCICR &= ~(0b00000010);
return 1;
case 'w':
print("iWRAP mode\n");
@ -299,7 +282,7 @@ static bool console_command(uint8_t c)
disable_vusb();
// enable suart receive interrut(PC5/PCINT13)
PCMSK1 |= 0b00100000;
PCICR |= 0b00000010;
PCICR |= 0b00000010;
return 1;
#endif
case 'k':
@ -315,62 +298,115 @@ static bool console_command(uint8_t c)
}
// convert keycode into ascii charactor
static uint8_t key2asc(uint8_t key)
{
static uint8_t key2asc(uint8_t key) {
switch (key) {
case KC_A: return 'a';
case KC_B: return 'b';
case KC_C: return 'c';
case KC_D: return 'd';
case KC_E: return 'e';
case KC_F: return 'f';
case KC_G: return 'g';
case KC_H: return 'h';
case KC_I: return 'i';
case KC_J: return 'j';
case KC_K: return 'k';
case KC_L: return 'l';
case KC_M: return 'm';
case KC_N: return 'n';
case KC_O: return 'o';
case KC_P: return 'p';
case KC_Q: return 'q';
case KC_R: return 'r';
case KC_S: return 's';
case KC_T: return 't';
case KC_U: return 'u';
case KC_V: return 'v';
case KC_W: return 'w';
case KC_X: return 'x';
case KC_Y: return 'y';
case KC_Z: return 'z';
case KC_1: return '1';
case KC_2: return '2';
case KC_3: return '3';
case KC_4: return '4';
case KC_5: return '5';
case KC_6: return '6';
case KC_7: return '7';
case KC_8: return '8';
case KC_9: return '9';
case KC_0: return '0';
case KC_ENTER: return '\n';
case KC_ESCAPE: return 0x1B;
case KC_BSPACE: return '\b';
case KC_TAB: return '\t';
case KC_SPACE: return ' ';
case KC_MINUS: return '-';
case KC_EQUAL: return '=';
case KC_LBRACKET: return '[';
case KC_RBRACKET: return ']';
case KC_BSLASH: return '\\';
case KC_NONUS_HASH: return '\\';
case KC_SCOLON: return ';';
case KC_QUOTE: return '\'';
case KC_GRAVE: return '`';
case KC_COMMA: return ',';
case KC_DOT: return '.';
case KC_SLASH: return '/';
default: return 0x00;
case KC_A:
return 'a';
case KC_B:
return 'b';
case KC_C:
return 'c';
case KC_D:
return 'd';
case KC_E:
return 'e';
case KC_F:
return 'f';
case KC_G:
return 'g';
case KC_H:
return 'h';
case KC_I:
return 'i';
case KC_J:
return 'j';
case KC_K:
return 'k';
case KC_L:
return 'l';
case KC_M:
return 'm';
case KC_N:
return 'n';
case KC_O:
return 'o';
case KC_P:
return 'p';
case KC_Q:
return 'q';
case KC_R:
return 'r';
case KC_S:
return 's';
case KC_T:
return 't';
case KC_U:
return 'u';
case KC_V:
return 'v';
case KC_W:
return 'w';
case KC_X:
return 'x';
case KC_Y:
return 'y';
case KC_Z:
return 'z';
case KC_1:
return '1';
case KC_2:
return '2';
case KC_3:
return '3';
case KC_4:
return '4';
case KC_5:
return '5';
case KC_6:
return '6';
case KC_7:
return '7';
case KC_8:
return '8';
case KC_9:
return '9';
case KC_0:
return '0';
case KC_ENTER:
return '\n';
case KC_ESCAPE:
return 0x1B;
case KC_BSPACE:
return '\b';
case KC_TAB:
return '\t';
case KC_SPACE:
return ' ';
case KC_MINUS:
return '-';
case KC_EQUAL:
return '=';
case KC_LBRACKET:
return '[';
case KC_RBRACKET:
return ']';
case KC_BSLASH:
return '\\';
case KC_NONUS_HASH:
return '\\';
case KC_SCOLON:
return ';';
case KC_QUOTE:
return '\'';
case KC_GRAVE:
return '`';
case KC_COMMA:
return ',';
case KC_DOT:
return '.';
case KC_SLASH:
return '/';
default:
return 0x00;
}
}

View file

@ -1,8 +1,8 @@
#ifndef SUART
#define SUART
void xmit(uint8_t);
void xmit(uint8_t);
uint8_t rcvr(void);
uint8_t recv(void);
#endif /* SUART */
#endif /* SUART */

View file

@ -61,55 +61,58 @@ cleared on every power up or reset, along with disabling the watchdog-
*/
//reset registers to the same name (MCUCSR)
// reset registers to the same name (MCUCSR)
#if !defined(MCUCSR)
#define MCUCSR MCUSR
# define MCUCSR MCUSR
#endif
//watchdog registers to the same name (WDTCSR)
// watchdog registers to the same name (WDTCSR)
#if !defined(WDTCSR)
#define WDTCSR WDTCR
# define WDTCSR WDTCR
#endif
//if enhanced watchdog, define irq values, create disable macro
// if enhanced watchdog, define irq values, create disable macro
#if defined(WDIF)
#define WD_IRQ 0xC0
#define WD_RST_IRQ 0xC8
#define WD_DISABLE() do{ \
MCUCSR &= ~(1<<WDRF); \
WD_SET(WD_OFF); \
}while(0)
# define WD_IRQ 0xC0
# define WD_RST_IRQ 0xC8
# define WD_DISABLE() \
do { \
MCUCSR &= ~(1 << WDRF); \
WD_SET(WD_OFF); \
} while (0)
#endif
//all watchdogs
#define WD_RST 8
#define WD_OFF 0
// all watchdogs
#define WD_RST 8
#define WD_OFF 0
//prescale values
#define WDTO_15MS 0
#define WDTO_30MS 1
#define WDTO_60MS 2
#define WDTO_120MS 3
#define WDTO_250MS 4
#define WDTO_500MS 5
#define WDTO_1S 6
#define WDTO_2S 7
// prescale values
#define WDTO_15MS 0
#define WDTO_30MS 1
#define WDTO_60MS 2
#define WDTO_120MS 3
#define WDTO_250MS 4
#define WDTO_500MS 5
#define WDTO_1S 6
#define WDTO_2S 7
//prescale values for avrs with WDP3
// prescale values for avrs with WDP3
#if defined(WDP3)
#define WDTO_4S 0x20
#define WDTO_8S 0x21
# define WDTO_4S 0x20
# define WDTO_8S 0x21
#endif
//watchdog reset
#define WDR() __asm__ __volatile__("wdr")
// watchdog reset
#define WDR() __asm__ __volatile__("wdr")
//avr reset using watchdog
#define WD_AVR_RESET() do{ \
__asm__ __volatile__("cli"); \
WD_SET_UNSAFE(WD_RST); \
while(1); \
}while(0)
// avr reset using watchdog
#define WD_AVR_RESET() \
do { \
__asm__ __volatile__("cli"); \
WD_SET_UNSAFE(WD_RST); \
while (1) \
; \
} while (0)
/*set the watchdog-
1. save SREG
@ -119,41 +122,40 @@ cleared on every power up or reset, along with disabling the watchdog-
5. write watchdog value
6. restore SREG (restoring irq status)
*/
#define WD_SET(val,...) \
__asm__ __volatile__( \
"in __tmp_reg__,__SREG__" "\n\t" \
"cli" "\n\t" \
"wdr" "\n\t" \
"sts %[wdreg],%[wden]" "\n\t" \
"sts %[wdreg],%[wdval]" "\n\t" \
"out __SREG__,__tmp_reg__" "\n\t" \
: \
: [wdreg] "M" (&WDTCSR), \
[wden] "r" ((uint8_t)(0x18)), \
[wdval] "r" ((uint8_t)(val|(__VA_ARGS__+0))) \
: "r0" \
)
#define WD_SET(val, ...) \
__asm__ __volatile__("in __tmp_reg__,__SREG__" \
"\n\t" \
"cli" \
"\n\t" \
"wdr" \
"\n\t" \
"sts %[wdreg],%[wden]" \
"\n\t" \
"sts %[wdreg],%[wdval]" \
"\n\t" \
"out __SREG__,__tmp_reg__" \
"\n\t" \
: \
: [ wdreg ] "M"(&WDTCSR), [ wden ] "r"((uint8_t)(0x18)), [ wdval ] "r"((uint8_t)(val | (__VA_ARGS__ + 0))) \
: "r0")
/*set the watchdog when I bit in SREG known to be clear-
1. reset watchdog timer
2. enable watchdog change
5. write watchdog value
*/
#define WD_SET_UNSAFE(val,...) \
__asm__ __volatile__( \
"wdr" "\n\t" \
"sts %[wdreg],%[wden]" "\n\t" \
"sts %[wdreg],%[wdval]" "\n\t" \
: \
: [wdreg] "M" (&WDTCSR), \
[wden] "r" ((uint8_t)(0x18)), \
[wdval] "r" ((uint8_t)(val|(__VA_ARGS__+0))) \
)
//for compatibility with avr/wdt.h
#define wdt_enable(val) WD_SET(WD_RST,val)
#define wdt_disable() WD_SET(WD_OFF)
#define WD_SET_UNSAFE(val, ...) \
__asm__ __volatile__("wdr" \
"\n\t" \
"sts %[wdreg],%[wden]" \
"\n\t" \
"sts %[wdreg],%[wdval]" \
"\n\t" \
: \
: [ wdreg ] "M"(&WDTCSR), [ wden ] "r"((uint8_t)(0x18)), [ wdval ] "r"((uint8_t)(val | (__VA_ARGS__ + 0))))
// for compatibility with avr/wdt.h
#define wdt_enable(val) WD_SET(WD_RST, val)
#define wdt_disable() WD_SET(WD_OFF)
#endif /* _AVR_WD_H_ */

File diff suppressed because it is too large Load diff

View file

@ -4,16 +4,16 @@
*/
#pragma once
#ifdef MODULE_ADAFRUIT_BLE
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
# include <stdbool.h>
# include <stdint.h>
# include <string.h>
#include "config_common.h"
#include "progmem.h"
# include "config_common.h"
# include "progmem.h"
#ifdef __cplusplus
# ifdef __cplusplus
extern "C" {
#endif
# endif
/* Instruct the module to enable HID keyboard support and reset */
extern bool adafruit_ble_enable_keyboard(void);
@ -34,20 +34,18 @@ extern void adafruit_ble_task(void);
* this set of keys.
* Also sends a key release indicator, so that the keys do not remain
* held down. */
extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys,
uint8_t nkeys);
extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uint8_t nkeys);
/* Send a consumer keycode, holding it down for the specified duration
* (milliseconds) */
extern bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration);
#ifdef MOUSE_ENABLE
# ifdef MOUSE_ENABLE
/* Send a mouse/wheel movement report.
* The parameters are signed and indicate positive of negative direction
* change. */
extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll,
int8_t pan, uint8_t buttons);
#endif
extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
# endif
/* Compute battery voltage by reading an analog pin.
* Returns the integer number of millivolts */
@ -56,8 +54,8 @@ extern uint32_t adafruit_ble_read_battery_voltage(void);
extern bool adafruit_ble_set_mode_leds(bool on);
extern bool adafruit_ble_set_power_level(int8_t level);
#ifdef __cplusplus
# ifdef __cplusplus
}
#endif
# endif
#endif // MODULE_ADAFRUIT_BLE
#endif // MODULE_ADAFRUIT_BLE

View file

@ -21,16 +21,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "debug.h"
#include "bluetooth.h"
void bluefruit_keyboard_print_report(report_keyboard_t *report)
{
void bluefruit_keyboard_print_report(report_keyboard_t *report) {
if (!debug_keyboard) return;
dprintf("keys: "); for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) { debug_hex8(report->keys[i]); dprintf(" "); }
dprintf(" mods: "); debug_hex8(report->mods);
dprintf(" reserved: "); debug_hex8(report->reserved);
dprintf("keys: ");
for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
debug_hex8(report->keys[i]);
dprintf(" ");
}
dprintf(" mods: ");
debug_hex8(report->mods);
dprintf(" reserved: ");
debug_hex8(report->reserved);
dprintf("\n");
}
void bluefruit_serial_send(uint8_t data)
{
serial_send(data);
}
void bluefruit_serial_send(uint8_t data) { serial_send(data); }

View file

@ -41,39 +41,8 @@ void bluefruit_serial_send(uint8_t data);
| Stop | 00000000 00010000 | 00 10 |
+-------------------------------------+-------+
*/
#define CONSUMER2BLUEFRUIT(usage) \
(usage == AUDIO_MUTE ? 0x0000 : \
(usage == AUDIO_VOL_UP ? 0x1000 : \
(usage == AUDIO_VOL_DOWN ? 0x2000 : \
(usage == TRANSPORT_NEXT_TRACK ? 0x0002 : \
(usage == TRANSPORT_PREV_TRACK ? 0x0004 : \
(usage == TRANSPORT_STOP ? 0x0010 : \
(usage == TRANSPORT_STOP_EJECT ? 0x0000 : \
(usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : \
(usage == AL_CC_CONFIG ? 0x0000 : \
(usage == AL_EMAIL ? 0x0000 : \
(usage == AL_CALCULATOR ? 0x0000 : \
(usage == AL_LOCAL_BROWSER ? 0x0000 : \
(usage == AC_SEARCH ? 0x0400 : \
(usage == AC_HOME ? 0x0100 : \
(usage == AC_BACK ? 0x0000 : \
(usage == AC_FORWARD ? 0x0000 : \
(usage == AC_STOP ? 0x0000 : \
(usage == AC_REFRESH ? 0x0000 : \
(usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
#define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
#define CONSUMER2RN42(usage) \
(usage == AUDIO_MUTE ? 0x0040 : \
(usage == AUDIO_VOL_UP ? 0x0010 : \
(usage == AUDIO_VOL_DOWN ? 0x0020 : \
(usage == TRANSPORT_NEXT_TRACK ? 0x0100 : \
(usage == TRANSPORT_PREV_TRACK ? 0x0200 : \
(usage == TRANSPORT_STOP ? 0x0400 : \
(usage == TRANSPORT_STOP_EJECT ? 0x0800 : \
(usage == TRANSPORT_PLAY_PAUSE ? 0x0080 : \
(usage == AL_EMAIL ? 0x0200 : \
(usage == AL_LOCAL_BROWSER ? 0x8000 : \
(usage == AC_SEARCH ? 0x0400 : \
(usage == AC_HOME ? 0x0100 : 0))))))))))))
#define CONSUMER2RN42(usage) (usage == AUDIO_MUTE ? 0x0040 : (usage == AUDIO_VOL_UP ? 0x0010 : (usage == AUDIO_VOL_DOWN ? 0x0020 : (usage == TRANSPORT_NEXT_TRACK ? 0x0100 : (usage == TRANSPORT_PREV_TRACK ? 0x0200 : (usage == TRANSPORT_STOP ? 0x0400 : (usage == TRANSPORT_STOP_EJECT ? 0x0800 : (usage == TRANSPORT_PLAY_PAUSE ? 0x0080 : (usage == AL_EMAIL ? 0x0200 : (usage == AL_LOCAL_BROWSER ? 0x8000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : 0))))))))))))
#endif
#endif

File diff suppressed because it is too large Load diff

View file

@ -62,27 +62,27 @@ extern host_driver_t lufa_driver;
typedef struct {
uint8_t report_id;
uint16_t usage;
} __attribute__ ((packed)) report_extra_t;
} __attribute__((packed)) report_extra_t;
#ifdef API_ENABLE
#include "api.h"
# include "api.h"
#endif
#ifdef API_SYSEX_ENABLE
#include "api_sysex.h"
// Allocate space for encoding overhead.
//The header and terminator are not stored to save a few bytes of precious ram
#define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
# include "api_sysex.h"
// Allocate space for encoding overhead.
// The header and terminator are not stored to save a few bytes of precious ram
# define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
#endif
// #if LUFA_VERSION_INTEGER < 0x120730
// /* old API 120219 */
// #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank)
// #else
/* new API >= 120730 */
#define ENDPOINT_BANK_SINGLE 1
#define ENDPOINT_BANK_DOUBLE 2
#define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum) , eptype, epsize, epbank)
/* new API >= 120730 */
#define ENDPOINT_BANK_SINGLE 1
#define ENDPOINT_BANK_DOUBLE 2
#define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum), eptype, epsize, epbank)
// #endif
#endif

View file

@ -15,7 +15,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "lufa.h"
#include "outputselect.h"
#ifdef MODULE_ADAFRUIT_BLE
#include "adafruit_ble.h"
# include "adafruit_ble.h"
#endif
uint8_t desired_output = OUTPUT_DEFAULT;
@ -33,9 +33,7 @@ void set_output(uint8_t output) {
*
* FIXME: Needs doc
*/
__attribute__((weak))
void set_output_user(uint8_t output) {
}
__attribute__((weak)) void set_output_user(uint8_t output) {}
/** \brief Auto Detect Output
*
@ -53,7 +51,7 @@ uint8_t auto_detect_output(void) {
#endif
#ifdef BLUETOOTH_ENABLE
return OUTPUT_BLUETOOTH; // should check if BT is connected here
return OUTPUT_BLUETOOTH; // should check if BT is connected here
#endif
return OUTPUT_NONE;
@ -69,4 +67,3 @@ uint8_t where_to_send(void) {
}
return desired_output;
}

View file

@ -27,14 +27,14 @@ enum outputs {
* backward compatibility for BLUETOOTH_ENABLE, send to BT and USB by default
*/
#ifndef OUTPUT_DEFAULT
#ifdef BLUETOOTH_ENABLE
#define OUTPUT_DEFAULT OUTPUT_USB_AND_BT
#else
#define OUTPUT_DEFAULT OUTPUT_AUTO
#endif
# ifdef BLUETOOTH_ENABLE
# define OUTPUT_DEFAULT OUTPUT_USB_AND_BT
# else
# define OUTPUT_DEFAULT OUTPUT_AUTO
# endif
#endif
void set_output(uint8_t output);
void set_output_user(uint8_t output);
void set_output(uint8_t output);
void set_output_user(uint8_t output);
uint8_t auto_detect_output(void);
uint8_t where_to_send(void);

View file

@ -43,98 +43,95 @@ POSSIBILITY OF SUCH DAMAGE.
#include "m0110.h"
#include "debug.h"
static inline uint8_t raw2scan(uint8_t raw);
static inline uint8_t inquiry(void);
static inline uint8_t instant(void);
static inline void clock_lo(void);
static inline void clock_hi(void);
static inline bool clock_in(void);
static inline void data_lo(void);
static inline void data_hi(void);
static inline bool data_in(void);
static inline uint8_t raw2scan(uint8_t raw);
static inline uint8_t inquiry(void);
static inline uint8_t instant(void);
static inline void clock_lo(void);
static inline void clock_hi(void);
static inline bool clock_in(void);
static inline void data_lo(void);
static inline void data_hi(void);
static inline bool data_in(void);
static inline uint16_t wait_clock_lo(uint16_t us);
static inline uint16_t wait_clock_hi(uint16_t us);
static inline uint16_t wait_data_lo(uint16_t us);
static inline uint16_t wait_data_hi(uint16_t us);
static inline void idle(void);
static inline void request(void);
static inline void idle(void);
static inline void request(void);
#define WAIT_US(stat, us, err) \
do { \
if (!wait_##stat(us)) { \
m0110_error = err; \
goto ERROR; \
} \
} while (0)
#define WAIT_US(stat, us, err) do { \
if (!wait_##stat(us)) { \
m0110_error = err; \
goto ERROR; \
} \
} while (0)
#define WAIT_MS(stat, ms, err) do { \
uint16_t _ms = ms; \
while (_ms) { \
if (wait_##stat(1000)) { \
break; \
} \
_ms--; \
} \
if (_ms == 0) { \
m0110_error = err; \
goto ERROR; \
} \
} while (0)
#define KEY(raw) ((raw) & 0x7f)
#define IS_BREAK(raw) (((raw) & 0x80) == 0x80)
#define WAIT_MS(stat, ms, err) \
do { \
uint16_t _ms = ms; \
while (_ms) { \
if (wait_##stat(1000)) { \
break; \
} \
_ms--; \
} \
if (_ms == 0) { \
m0110_error = err; \
goto ERROR; \
} \
} while (0)
#define KEY(raw) ((raw)&0x7f)
#define IS_BREAK(raw) (((raw)&0x80) == 0x80)
uint8_t m0110_error = 0;
void m0110_init(void)
{
void m0110_init(void) {
idle();
_delay_ms(1000);
/* Not needed to initialize in fact.
uint8_t data;
m0110_send(M0110_MODEL);
data = m0110_recv();
print("m0110_init model: "); phex(data); print("\n");
/* Not needed to initialize in fact.
uint8_t data;
m0110_send(M0110_MODEL);
data = m0110_recv();
print("m0110_init model: "); phex(data); print("\n");
m0110_send(M0110_TEST);
data = m0110_recv();
print("m0110_init test: "); phex(data); print("\n");
*/
m0110_send(M0110_TEST);
data = m0110_recv();
print("m0110_init test: "); phex(data); print("\n");
*/
}
uint8_t m0110_send(uint8_t data)
{
uint8_t m0110_send(uint8_t data) {
m0110_error = 0;
request();
WAIT_MS(clock_lo, 250, 1); // keyboard may block long time
for (uint8_t bit = 0x80; bit; bit >>= 1) {
WAIT_US(clock_lo, 250, 3);
if (data&bit) {
if (data & bit) {
data_hi();
} else {
data_lo();
}
WAIT_US(clock_hi, 200, 4);
}
_delay_us(100); // hold last bit for 80us
_delay_us(100); // hold last bit for 80us
idle();
return 1;
ERROR:
print("m0110_send err: "); phex(m0110_error); print("\n");
print("m0110_send err: ");
phex(m0110_error);
print("\n");
_delay_ms(500);
idle();
return 0;
}
uint8_t m0110_recv(void)
{
uint8_t m0110_recv(void) {
uint8_t data = 0;
m0110_error = 0;
m0110_error = 0;
WAIT_MS(clock_lo, 250, 1); // keyboard may block long time
for (uint8_t i = 0; i < 8; i++) {
@ -148,7 +145,9 @@ uint8_t m0110_recv(void)
idle();
return data;
ERROR:
print("m0110_recv err: "); phex(m0110_error); print("\n");
print("m0110_recv err: ");
phex(m0110_error);
print("\n");
_delay_ms(500);
idle();
return 0xFF;
@ -199,26 +198,25 @@ During Calc key is hold:
*b: Shift(d) event is ignored.
*c: Arrow/Calc(d) event is ignored.
*/
uint8_t m0110_recv_key(void)
{
static uint8_t keybuf = 0x00;
uint8_t m0110_recv_key(void) {
static uint8_t keybuf = 0x00;
static uint8_t keybuf2 = 0x00;
static uint8_t rawbuf = 0x00;
uint8_t raw, raw2, raw3;
static uint8_t rawbuf = 0x00;
uint8_t raw, raw2, raw3;
if (keybuf) {
raw = keybuf;
raw = keybuf;
keybuf = 0x00;
return raw;
}
if (keybuf2) {
raw = keybuf2;
raw = keybuf2;
keybuf2 = 0x00;
return raw;
}
if (rawbuf) {
raw = rawbuf;
raw = rawbuf;
rawbuf = 0x00;
} else {
raw = instant(); // Use INSTANT for better response. Should be INQUIRY ?
@ -233,8 +231,8 @@ uint8_t m0110_recv_key(void)
case M0110_ARROW_RIGHT:
if (IS_BREAK(raw2)) {
// Case B,F,N:
keybuf = (raw2scan(raw2) | M0110_CALC_OFFSET); // Calc(u)
return (raw2scan(raw2) | M0110_KEYPAD_OFFSET); // Arrow(u)
keybuf = (raw2scan(raw2) | M0110_CALC_OFFSET); // Calc(u)
return (raw2scan(raw2) | M0110_KEYPAD_OFFSET); // Arrow(u)
}
break;
}
@ -247,7 +245,7 @@ uint8_t m0110_recv_key(void)
case M0110_SHIFT:
// Case: 5-8,C,G,H
rawbuf = raw2;
return raw2scan(raw); // Shift(d/u)
return raw2scan(raw); // Shift(d/u)
break;
case M0110_KEYPAD:
// Shift + Arrow, Calc, or etc.
@ -261,38 +259,38 @@ uint8_t m0110_recv_key(void)
if (IS_BREAK(raw3)) {
// Case 4:
print("(4)\n");
keybuf2 = raw2scan(raw); // Shift(u)
keybuf = (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(u)
return (raw2scan(raw3) | M0110_KEYPAD_OFFSET); // Arrow(u)
keybuf2 = raw2scan(raw); // Shift(u)
keybuf = (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(u)
return (raw2scan(raw3) | M0110_KEYPAD_OFFSET); // Arrow(u)
} else {
// Case 3:
print("(3)\n");
return (raw2scan(raw)); // Shift(u)
return (raw2scan(raw)); // Shift(u)
}
} else {
if (IS_BREAK(raw3)) {
// Case 2:
print("(2)\n");
keybuf = (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(u)
keybuf = (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(u)
return (raw2scan(raw3) | M0110_KEYPAD_OFFSET); // Arrow(u)
} else {
// Case 1:
print("(1)\n");
return (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(d)
return (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(d)
}
}
break;
default:
// Shift + Keypad
keybuf = (raw2scan(raw3) | M0110_KEYPAD_OFFSET);
return raw2scan(raw); // Shift(d/u)
return raw2scan(raw); // Shift(d/u)
break;
}
break;
default:
// Shift + Normal keys
keybuf = raw2scan(raw2);
return raw2scan(raw); // Shift(d/u)
return raw2scan(raw); // Shift(d/u)
break;
}
break;
@ -303,103 +301,97 @@ uint8_t m0110_recv_key(void)
}
}
static inline uint8_t raw2scan(uint8_t raw) { return (raw == M0110_NULL) ? M0110_NULL : ((raw == M0110_ERROR) ? M0110_ERROR : (((raw & 0x80) | ((raw & 0x7F) >> 1)))); }
static inline uint8_t raw2scan(uint8_t raw) {
return (raw == M0110_NULL) ? M0110_NULL : (
(raw == M0110_ERROR) ? M0110_ERROR : (
((raw&0x80) | ((raw&0x7F)>>1))
)
);
}
static inline uint8_t inquiry(void)
{
static inline uint8_t inquiry(void) {
m0110_send(M0110_INQUIRY);
return m0110_recv();
}
static inline uint8_t instant(void)
{
static inline uint8_t instant(void) {
m0110_send(M0110_INSTANT);
uint8_t data = m0110_recv();
if (data != M0110_NULL) {
debug_hex(data); debug(" ");
debug_hex(data);
debug(" ");
}
return data;
}
static inline void clock_lo()
{
M0110_CLOCK_PORT &= ~(1<<M0110_CLOCK_BIT);
M0110_CLOCK_DDR |= (1<<M0110_CLOCK_BIT);
static inline void clock_lo() {
M0110_CLOCK_PORT &= ~(1 << M0110_CLOCK_BIT);
M0110_CLOCK_DDR |= (1 << M0110_CLOCK_BIT);
}
static inline void clock_hi()
{
static inline void clock_hi() {
/* input with pull up */
M0110_CLOCK_DDR &= ~(1<<M0110_CLOCK_BIT);
M0110_CLOCK_PORT |= (1<<M0110_CLOCK_BIT);
M0110_CLOCK_DDR &= ~(1 << M0110_CLOCK_BIT);
M0110_CLOCK_PORT |= (1 << M0110_CLOCK_BIT);
}
static inline bool clock_in()
{
M0110_CLOCK_DDR &= ~(1<<M0110_CLOCK_BIT);
M0110_CLOCK_PORT |= (1<<M0110_CLOCK_BIT);
static inline bool clock_in() {
M0110_CLOCK_DDR &= ~(1 << M0110_CLOCK_BIT);
M0110_CLOCK_PORT |= (1 << M0110_CLOCK_BIT);
_delay_us(1);
return M0110_CLOCK_PIN&(1<<M0110_CLOCK_BIT);
return M0110_CLOCK_PIN & (1 << M0110_CLOCK_BIT);
}
static inline void data_lo()
{
M0110_DATA_PORT &= ~(1<<M0110_DATA_BIT);
M0110_DATA_DDR |= (1<<M0110_DATA_BIT);
static inline void data_lo() {
M0110_DATA_PORT &= ~(1 << M0110_DATA_BIT);
M0110_DATA_DDR |= (1 << M0110_DATA_BIT);
}
static inline void data_hi()
{
static inline void data_hi() {
/* input with pull up */
M0110_DATA_DDR &= ~(1<<M0110_DATA_BIT);
M0110_DATA_PORT |= (1<<M0110_DATA_BIT);
M0110_DATA_DDR &= ~(1 << M0110_DATA_BIT);
M0110_DATA_PORT |= (1 << M0110_DATA_BIT);
}
static inline bool data_in()
{
M0110_DATA_DDR &= ~(1<<M0110_DATA_BIT);
M0110_DATA_PORT |= (1<<M0110_DATA_BIT);
static inline bool data_in() {
M0110_DATA_DDR &= ~(1 << M0110_DATA_BIT);
M0110_DATA_PORT |= (1 << M0110_DATA_BIT);
_delay_us(1);
return M0110_DATA_PIN&(1<<M0110_DATA_BIT);
return M0110_DATA_PIN & (1 << M0110_DATA_BIT);
}
static inline uint16_t wait_clock_lo(uint16_t us)
{
while (clock_in() && us) { asm(""); _delay_us(1); us--; }
static inline uint16_t wait_clock_lo(uint16_t us) {
while (clock_in() && us) {
asm("");
_delay_us(1);
us--;
}
return us;
}
static inline uint16_t wait_clock_hi(uint16_t us)
{
while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
static inline uint16_t wait_clock_hi(uint16_t us) {
while (!clock_in() && us) {
asm("");
_delay_us(1);
us--;
}
return us;
}
static inline uint16_t wait_data_lo(uint16_t us)
{
while (data_in() && us) { asm(""); _delay_us(1); us--; }
static inline uint16_t wait_data_lo(uint16_t us) {
while (data_in() && us) {
asm("");
_delay_us(1);
us--;
}
return us;
}
static inline uint16_t wait_data_hi(uint16_t us)
{
while (!data_in() && us) { asm(""); _delay_us(1); us--; }
static inline uint16_t wait_data_hi(uint16_t us) {
while (!data_in() && us) {
asm("");
_delay_us(1);
us--;
}
return us;
}
static inline void idle(void)
{
static inline void idle(void) {
clock_hi();
data_hi();
}
static inline void request(void)
{
static inline void request(void) {
clock_hi();
data_lo();
}
/*
Primitive M0110 Library for AVR
==============================

View file

@ -38,51 +38,43 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef M0110_H
#define M0110_H
/* port settings for clock and data line */
#if !(defined(M0110_CLOCK_PORT) && \
defined(M0110_CLOCK_PIN) && \
defined(M0110_CLOCK_DDR) && \
defined(M0110_CLOCK_BIT))
# error "M0110 clock port setting is required in config.h"
#if !(defined(M0110_CLOCK_PORT) && defined(M0110_CLOCK_PIN) && defined(M0110_CLOCK_DDR) && defined(M0110_CLOCK_BIT))
# error "M0110 clock port setting is required in config.h"
#endif
#if !(defined(M0110_DATA_PORT) && \
defined(M0110_DATA_PIN) && \
defined(M0110_DATA_DDR) && \
defined(M0110_DATA_BIT))
# error "M0110 data port setting is required in config.h"
#if !(defined(M0110_DATA_PORT) && defined(M0110_DATA_PIN) && defined(M0110_DATA_DDR) && defined(M0110_DATA_BIT))
# error "M0110 data port setting is required in config.h"
#endif
/* Commands */
#define M0110_INQUIRY 0x10
#define M0110_INSTANT 0x14
#define M0110_MODEL 0x16
#define M0110_TEST 0x36
#define M0110_INQUIRY 0x10
#define M0110_INSTANT 0x14
#define M0110_MODEL 0x16
#define M0110_TEST 0x36
/* Response(raw byte from M0110) */
#define M0110_NULL 0x7B
#define M0110_KEYPAD 0x79
#define M0110_TEST_ACK 0x7D
#define M0110_TEST_NAK 0x77
#define M0110_SHIFT 0x71
#define M0110_ARROW_UP 0x1B
#define M0110_ARROW_DOWN 0x11
#define M0110_ARROW_LEFT 0x0D
#define M0110_ARROW_RIGHT 0x05
#define M0110_NULL 0x7B
#define M0110_KEYPAD 0x79
#define M0110_TEST_ACK 0x7D
#define M0110_TEST_NAK 0x77
#define M0110_SHIFT 0x71
#define M0110_ARROW_UP 0x1B
#define M0110_ARROW_DOWN 0x11
#define M0110_ARROW_LEFT 0x0D
#define M0110_ARROW_RIGHT 0x05
/* This inidcates no response. */
#define M0110_ERROR 0xFF
#define M0110_ERROR 0xFF
/* scan code offset for keypad and arrow keys */
#define M0110_KEYPAD_OFFSET 0x40
#define M0110_CALC_OFFSET 0x60
#define M0110_CALC_OFFSET 0x60
extern uint8_t m0110_error;
/* host role */
void m0110_init(void);
void m0110_init(void);
uint8_t m0110_send(uint8_t data);
uint8_t m0110_recv(void);
uint8_t m0110_recv_key(void);

View file

@ -6,20 +6,14 @@
#define DEFAULT_CONFIGURATION (1)
HIDKeyboard::HIDKeyboard(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release)
{
USBDevice::connect();
}
HIDKeyboard::HIDKeyboard(uint16_t vendor_id, uint16_t product_id, uint16_t product_release) : USBDevice(vendor_id, product_id, product_release) { USBDevice::connect(); }
bool HIDKeyboard::sendReport(report_keyboard_t report) {
USBDevice::write(EP1IN, report.raw, sizeof(report), MAX_PACKET_SIZE_EP1);
return true;
}
uint8_t HIDKeyboard::leds() {
return led_state;
}
uint8_t HIDKeyboard::leds() { return led_state; }
bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) {
if (configuration != DEFAULT_CONFIGURATION) {
@ -28,80 +22,86 @@ bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) {
// Configure endpoints > 0
addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
//addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
// addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
// We activate the endpoint to be able to recceive data
//readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
// readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
return true;
}
uint8_t * HIDKeyboard::stringImanufacturerDesc() {
uint8_t *HIDKeyboard::stringImanufacturerDesc() {
static uint8_t stringImanufacturerDescriptor[] = {
0x18, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
't',0,'m',0,'k',0,'-',0,'k',0,'b',0,'d',0,'.',0,'c',0,'o',0,'m',0 /*bString iManufacturer*/
0x18, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
't',
0,
'm',
0,
'k',
0,
'-',
0,
'k',
0,
'b',
0,
'd',
0,
'.',
0,
'c',
0,
'o',
0,
'm',
0 /*bString iManufacturer*/
};
return stringImanufacturerDescriptor;
}
uint8_t * HIDKeyboard::stringIproductDesc() {
uint8_t *HIDKeyboard::stringIproductDesc() {
static uint8_t stringIproductDescriptor[] = {
0x0a, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'm',0,'b',0,'e',0,'d',0 /*bString iProduct*/
0x0a, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'm',
0,
'b',
0,
'e',
0,
'd',
0 /*bString iProduct*/
};
return stringIproductDescriptor;
}
uint8_t * HIDKeyboard::stringIserialDesc() {
uint8_t *HIDKeyboard::stringIserialDesc() {
static uint8_t stringIserialDescriptor[] = {
0x04, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'0',0 /*bString iSerial*/
0x04, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'0', 0 /*bString iSerial*/
};
return stringIserialDescriptor;
}
uint8_t * HIDKeyboard::reportDesc() {
uint8_t *HIDKeyboard::reportDesc() {
static uint8_t reportDescriptor[] = {
USAGE_PAGE(1), 0x01, // Generic Desktop
USAGE(1), 0x06, // Keyboard
COLLECTION(1), 0x01, // Application
USAGE_PAGE(1), 0x01, // Generic Desktop
USAGE(1), 0x06, // Keyboard
COLLECTION(1), 0x01, // Application
USAGE_PAGE(1), 0x07, // Key Codes
USAGE_MINIMUM(1), 0xE0,
USAGE_MAXIMUM(1), 0xE7,
LOGICAL_MINIMUM(1), 0x00,
LOGICAL_MAXIMUM(1), 0x01,
REPORT_SIZE(1), 0x01,
REPORT_COUNT(1), 0x08,
INPUT(1), 0x02, // Data, Variable, Absolute
USAGE_PAGE(1), 0x07, // Key Codes
USAGE_MINIMUM(1), 0xE0, USAGE_MAXIMUM(1), 0xE7, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0x01, REPORT_SIZE(1), 0x01, REPORT_COUNT(1), 0x08, INPUT(1), 0x02, // Data, Variable, Absolute
REPORT_COUNT(1), 0x01,
REPORT_SIZE(1), 0x08,
INPUT(1), 0x01, // Constant
REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x08, INPUT(1), 0x01, // Constant
REPORT_COUNT(1), 0x05,
REPORT_SIZE(1), 0x01,
USAGE_PAGE(1), 0x08, // LEDs
USAGE_MINIMUM(1), 0x01,
USAGE_MAXIMUM(1), 0x05,
OUTPUT(1), 0x02, // Data, Variable, Absolute
REPORT_COUNT(1), 0x05, REPORT_SIZE(1), 0x01, USAGE_PAGE(1), 0x08, // LEDs
USAGE_MINIMUM(1), 0x01, USAGE_MAXIMUM(1), 0x05, OUTPUT(1), 0x02, // Data, Variable, Absolute
REPORT_COUNT(1), 0x01,
REPORT_SIZE(1), 0x03,
OUTPUT(1), 0x01, // Constant
REPORT_COUNT(1), 0x01, REPORT_SIZE(1), 0x03, OUTPUT(1), 0x01, // Constant
REPORT_COUNT(1), 0x06,
REPORT_SIZE(1), 0x08,
LOGICAL_MINIMUM(1), 0x00,
LOGICAL_MAXIMUM(1), 0xFF,
USAGE_PAGE(1), 0x07, // Key Codes
USAGE_MINIMUM(1), 0x00,
USAGE_MAXIMUM(1), 0xFF,
INPUT(1), 0x00, // Data, Array
REPORT_COUNT(1), 0x06, REPORT_SIZE(1), 0x08, LOGICAL_MINIMUM(1), 0x00, LOGICAL_MAXIMUM(1), 0xFF, USAGE_PAGE(1), 0x07, // Key Codes
USAGE_MINIMUM(1), 0x00, USAGE_MAXIMUM(1), 0xFF, INPUT(1), 0x00, // Data, Array
END_COLLECTION(0),
};
reportLength = sizeof(reportDescriptor);
@ -113,48 +113,45 @@ uint16_t HIDKeyboard::reportDescLength() {
return reportLength;
}
#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
+ (1 * INTERFACE_DESCRIPTOR_LENGTH) \
+ (1 * HID_DESCRIPTOR_LENGTH) \
+ (1 * ENDPOINT_DESCRIPTOR_LENGTH))
uint8_t * HIDKeyboard::configurationDesc() {
#define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) + (1 * INTERFACE_DESCRIPTOR_LENGTH) + (1 * HID_DESCRIPTOR_LENGTH) + (1 * ENDPOINT_DESCRIPTOR_LENGTH))
uint8_t *HIDKeyboard::configurationDesc() {
static uint8_t configurationDescriptor[] = {
CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
CONFIGURATION_DESCRIPTOR, // bDescriptorType
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
0x01, // bNumInterfaces
DEFAULT_CONFIGURATION, // bConfigurationValue
0x00, // iConfiguration
C_RESERVED | C_REMOTE_WAKEUP, // bmAttributes
C_POWER(100), // bMaxPowerHello World from Mbed
CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
CONFIGURATION_DESCRIPTOR, // bDescriptorType
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
0x01, // bNumInterfaces
DEFAULT_CONFIGURATION, // bConfigurationValue
0x00, // iConfiguration
C_RESERVED | C_REMOTE_WAKEUP, // bmAttributes
C_POWER(100), // bMaxPowerHello World from Mbed
INTERFACE_DESCRIPTOR_LENGTH, // bLength
INTERFACE_DESCRIPTOR, // bDescriptorType
0x00, // bInterfaceNumber
0x00, // bAlternateSetting
0x01, // bNumEndpoints
HID_CLASS, // bInterfaceClass
1, // bInterfaceSubClass (boot)
1, // bInterfaceProtocol (keyboard)
0x00, // iInterface
INTERFACE_DESCRIPTOR_LENGTH, // bLength
INTERFACE_DESCRIPTOR, // bDescriptorType
0x00, // bInterfaceNumber
0x00, // bAlternateSetting
0x01, // bNumEndpoints
HID_CLASS, // bInterfaceClass
1, // bInterfaceSubClass (boot)
1, // bInterfaceProtocol (keyboard)
0x00, // iInterface
HID_DESCRIPTOR_LENGTH, // bLength
HID_DESCRIPTOR, // bDescriptorType
LSB(HID_VERSION_1_11), // bcdHID (LSB)
MSB(HID_VERSION_1_11), // bcdHID (MSB)
0x00, // bCountryCode
0x01, // bNumDescriptors
REPORT_DESCRIPTOR, // bDescriptorType
HID_DESCRIPTOR_LENGTH, // bLength
HID_DESCRIPTOR, // bDescriptorType
LSB(HID_VERSION_1_11), // bcdHID (LSB)
MSB(HID_VERSION_1_11), // bcdHID (MSB)
0x00, // bCountryCode
0x01, // bNumDescriptors
REPORT_DESCRIPTOR, // bDescriptorType
(uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
(uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
ENDPOINT_DESCRIPTOR, // bDescriptorType
PHY_TO_DESC(EP1IN), // bEndpointAddress
E_INTERRUPT, // bmAttributes
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
ENDPOINT_DESCRIPTOR, // bDescriptorType
PHY_TO_DESC(EP1IN), // bEndpointAddress
E_INTERRUPT, // bmAttributes
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
1, // bInterval (milliseconds)
};
return configurationDescriptor;
@ -187,41 +184,35 @@ uint8_t * HIDKeyboard::deviceDesc() {
#endif
bool HIDKeyboard::USBCallback_request() {
bool success = false;
CONTROL_TRANSFER * transfer = getTransferPtr();
uint8_t *hidDescriptor;
bool success = false;
CONTROL_TRANSFER *transfer = getTransferPtr();
uint8_t * hidDescriptor;
// Process additional standard requests
if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE))
{
switch (transfer->setup.bRequest)
{
if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE)) {
switch (transfer->setup.bRequest) {
case GET_DESCRIPTOR:
switch (DESCRIPTOR_TYPE(transfer->setup.wValue))
{
switch (DESCRIPTOR_TYPE(transfer->setup.wValue)) {
case REPORT_DESCRIPTOR:
if ((reportDesc() != NULL) \
&& (reportDescLength() != 0))
{
if ((reportDesc() != NULL) && (reportDescLength() != 0)) {
transfer->remaining = reportDescLength();
transfer->ptr = reportDesc();
transfer->ptr = reportDesc();
transfer->direction = DEVICE_TO_HOST;
success = true;
success = true;
}
break;
case HID_DESCRIPTOR:
// Find the HID descriptor, after the configuration descriptor
hidDescriptor = findDescriptor(HID_DESCRIPTOR);
if (hidDescriptor != NULL)
{
transfer->remaining = HID_DESCRIPTOR_LENGTH;
transfer->ptr = hidDescriptor;
transfer->direction = DEVICE_TO_HOST;
success = true;
}
break;
// Find the HID descriptor, after the configuration descriptor
hidDescriptor = findDescriptor(HID_DESCRIPTOR);
if (hidDescriptor != NULL) {
transfer->remaining = HID_DESCRIPTOR_LENGTH;
transfer->ptr = hidDescriptor;
transfer->direction = DEVICE_TO_HOST;
success = true;
}
break;
default:
break;
}
@ -232,8 +223,7 @@ bool HIDKeyboard::USBCallback_request() {
}
// Process class-specific requests
if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
{
if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
switch (transfer->setup.bRequest) {
case SET_REPORT:
// LED indicator
@ -242,10 +232,10 @@ bool HIDKeyboard::USBCallback_request() {
// if (transfer->setup.wLength == 1)
transfer->remaining = 1;
//transfer->ptr = ?? what ptr should be set when OUT(not used?)
// transfer->ptr = ?? what ptr should be set when OUT(not used?)
transfer->direction = HOST_TO_DEVICE;
transfer->notify = true; /* notify with USBCallback_requestCompleted */
success = true;
transfer->notify = true; /* notify with USBCallback_requestCompleted */
success = true;
default:
break;
}
@ -254,8 +244,7 @@ bool HIDKeyboard::USBCallback_request() {
return success;
}
void HIDKeyboard::USBCallback_requestCompleted(uint8_t * buf, uint32_t length)
{
void HIDKeyboard::USBCallback_requestCompleted(uint8_t *buf, uint32_t length) {
if (length > 0) {
CONTROL_TRANSFER *transfer = getTransferPtr();
if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {

View file

@ -1,30 +1,31 @@
#ifndef HIDKEYBOARD_H
#include "stdint.h"
#include "stdbool.h"
#include "USBHID.h"
#include "report.h"
# include "stdint.h"
# include "stdbool.h"
# include "USBHID.h"
# include "report.h"
class HIDKeyboard : public USBDevice {
public:
public:
HIDKeyboard(uint16_t vendor_id = 0xFEED, uint16_t product_id = 0xabed, uint16_t product_release = 0x0001);
bool sendReport(report_keyboard_t report);
bool sendReport(report_keyboard_t report);
uint8_t leds(void);
protected:
uint16_t reportLength;
virtual bool USBCallback_setConfiguration(uint8_t configuration);
virtual uint8_t * stringImanufacturerDesc();
virtual uint8_t * stringIproductDesc();
virtual uint8_t * stringIserialDesc();
protected:
uint16_t reportLength;
virtual bool USBCallback_setConfiguration(uint8_t configuration);
virtual uint8_t* stringImanufacturerDesc();
virtual uint8_t* stringIproductDesc();
virtual uint8_t* stringIserialDesc();
virtual uint16_t reportDescLength();
virtual uint8_t * reportDesc();
virtual uint8_t * configurationDesc();
//virtual uint8_t * deviceDesc();
virtual uint8_t* reportDesc();
virtual uint8_t* configurationDesc();
// virtual uint8_t * deviceDesc();
virtual bool USBCallback_request();
virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length);
private:
virtual void USBCallback_requestCompleted(uint8_t* buf, uint32_t length);
private:
uint8_t led_state;
};

View file

@ -5,37 +5,17 @@
HIDKeyboard keyboard;
/* Host driver */
static uint8_t keyboard_leds(void);
static void send_keyboard(report_keyboard_t *report);
static void send_mouse(report_mouse_t *report);
static void send_system(uint16_t data);
static void send_consumer(uint16_t data);
static void send_keyboard(report_keyboard_t *report);
static void send_mouse(report_mouse_t *report);
static void send_system(uint16_t data);
static void send_consumer(uint16_t data);
host_driver_t mbed_driver = {
keyboard_leds,
send_keyboard,
send_mouse,
send_system,
send_consumer
};
host_driver_t mbed_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
static uint8_t keyboard_leds(void)
{
return keyboard.leds();
}
static void send_keyboard(report_keyboard_t *report)
{
keyboard.sendReport(*report);
}
static void send_mouse(report_mouse_t *report)
{
}
static void send_system(uint16_t data)
{
}
static void send_consumer(uint16_t data)
{
}
static uint8_t keyboard_leds(void) { return keyboard.leds(); }
static void send_keyboard(report_keyboard_t *report) { keyboard.sendReport(*report); }
static void send_mouse(report_mouse_t *report) {}
static void send_system(uint16_t data) {}
static void send_consumer(uint16_t data) {}

28
tmk_core/protocol/midi/Config/LUFAConfig.h Executable file → Normal file
View file

@ -42,12 +42,12 @@
#ifndef _LUFA_CONFIG_H_
#define _LUFA_CONFIG_H_
#if (ARCH == ARCH_AVR8)
#if (ARCH == ARCH_AVR8)
/* Non-USB Related Configuration Tokens: */
/* Non-USB Related Configuration Tokens: */
// #define DISABLE_TERMINAL_CODES
/* USB Class Driver Related Tokens: */
/* USB Class Driver Related Tokens: */
// #define HID_HOST_BOOT_PROTOCOL_ONLY
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
@ -56,38 +56,38 @@
// #define HID_MAX_REPORT_IDS {Insert Value Here}
// #define NO_CLASS_DRIVER_AUTOFLUSH
/* General USB Driver Related Tokens: */
/* General USB Driver Related Tokens: */
// #define ORDERED_EP_CONFIG
#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
#define USB_DEVICE_ONLY
# define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
# define USB_DEVICE_ONLY
// #define USB_HOST_ONLY
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
// #define NO_LIMITED_CONTROLLER_CONNECT
// #define NO_SOF_EVENTS
/* USB Device Mode Driver Related Tokens: */
/* USB Device Mode Driver Related Tokens: */
// #define USE_RAM_DESCRIPTORS
#define USE_FLASH_DESCRIPTORS
# define USE_FLASH_DESCRIPTORS
// #define USE_EEPROM_DESCRIPTORS
// #define NO_INTERNAL_SERIAL
#define FIXED_CONTROL_ENDPOINT_SIZE 8
# define FIXED_CONTROL_ENDPOINT_SIZE 8
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
#define FIXED_NUM_CONFIGURATIONS 1
# define FIXED_NUM_CONFIGURATIONS 1
// #define CONTROL_ONLY_DEVICE
// #define INTERRUPT_CONTROL_ENDPOINT
// #define NO_DEVICE_REMOTE_WAKEUP
// #define NO_DEVICE_SELF_POWER
/* USB Host Mode Driver Related Tokens: */
/* USB Host Mode Driver Related Tokens: */
// #define HOST_STATE_AS_GPIOR {Insert Value Here}
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
// #define NO_AUTO_VBUS_MANAGEMENT
// #define INVERTED_VBUS_ENABLE_LINE
#else
#else
#error Unsupported architecture for this LUFA configuration file.
# error Unsupported architecture for this LUFA configuration file.
#endif
#endif
#endif

93
tmk_core/protocol/midi/bytequeue/bytequeue.c Executable file → Normal file
View file

@ -1,65 +1,62 @@
//this is a single reader [maybe multiple writer?] byte queue
//Copyright 2008 Alex Norman
//writen by Alex Norman
// this is a single reader [maybe multiple writer?] byte queue
// Copyright 2008 Alex Norman
// writen by Alex Norman
//
//This file is part of avr-bytequeue.
// This file is part of avr-bytequeue.
//
//avr-bytequeue is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-bytequeue is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-bytequeue is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-bytequeue is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
#include "bytequeue.h"
#include "interrupt_setting.h"
void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen){
queue->length = arrayLen;
queue->data = dataArray;
queue->start = queue->end = 0;
void bytequeue_init(byteQueue_t* queue, uint8_t* dataArray, byteQueueIndex_t arrayLen) {
queue->length = arrayLen;
queue->data = dataArray;
queue->start = queue->end = 0;
}
bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item){
interrupt_setting_t setting = store_and_clear_interrupt();
//full
if(((queue->end + 1) % queue->length) == queue->start){
restore_interrupt_setting(setting);
return false;
} else {
queue->data[queue->end] = item;
queue->end = (queue->end + 1) % queue->length;
restore_interrupt_setting(setting);
return true;
}
bool bytequeue_enqueue(byteQueue_t* queue, uint8_t item) {
interrupt_setting_t setting = store_and_clear_interrupt();
// full
if (((queue->end + 1) % queue->length) == queue->start) {
restore_interrupt_setting(setting);
return false;
} else {
queue->data[queue->end] = item;
queue->end = (queue->end + 1) % queue->length;
restore_interrupt_setting(setting);
return true;
}
}
byteQueueIndex_t bytequeue_length(byteQueue_t * queue){
byteQueueIndex_t len;
interrupt_setting_t setting = store_and_clear_interrupt();
if(queue->end >= queue->start)
len = queue->end - queue->start;
else
len = (queue->length - queue->start) + queue->end;
restore_interrupt_setting(setting);
return len;
byteQueueIndex_t bytequeue_length(byteQueue_t* queue) {
byteQueueIndex_t len;
interrupt_setting_t setting = store_and_clear_interrupt();
if (queue->end >= queue->start)
len = queue->end - queue->start;
else
len = (queue->length - queue->start) + queue->end;
restore_interrupt_setting(setting);
return len;
}
//we don't need to avoid interrupts if there is only one reader
uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index){
return queue->data[(queue->start + index) % queue->length];
}
// we don't need to avoid interrupts if there is only one reader
uint8_t bytequeue_get(byteQueue_t* queue, byteQueueIndex_t index) { return queue->data[(queue->start + index) % queue->length]; }
//we just update the start index to remove elements
void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove){
interrupt_setting_t setting = store_and_clear_interrupt();
queue->start = (queue->start + numToRemove) % queue->length;
restore_interrupt_setting(setting);
// we just update the start index to remove elements
void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove) {
interrupt_setting_t setting = store_and_clear_interrupt();
queue->start = (queue->start + numToRemove) % queue->length;
restore_interrupt_setting(setting);
}

59
tmk_core/protocol/midi/bytequeue/bytequeue.h Executable file → Normal file
View file

@ -1,28 +1,28 @@
//this is a single reader [maybe multiple writer?] byte queue
//Copyright 2008 Alex Norman
//writen by Alex Norman
// this is a single reader [maybe multiple writer?] byte queue
// Copyright 2008 Alex Norman
// writen by Alex Norman
//
//This file is part of avr-bytequeue.
// This file is part of avr-bytequeue.
//
//avr-bytequeue is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-bytequeue is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-bytequeue is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-bytequeue is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
#ifndef BYTEQUEUE_H
#define BYTEQUEUE_H
#ifdef __cplusplus
extern "C" {
#endif
#endif
#include <inttypes.h>
#include <stdbool.h>
@ -30,30 +30,29 @@ extern "C" {
typedef uint8_t byteQueueIndex_t;
typedef struct {
byteQueueIndex_t start;
byteQueueIndex_t end;
byteQueueIndex_t length;
uint8_t * data;
byteQueueIndex_t start;
byteQueueIndex_t end;
byteQueueIndex_t length;
uint8_t* data;
} byteQueue_t;
//you must have a queue, an array of data which the queue will use, and the length of that array
void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen);
// you must have a queue, an array of data which the queue will use, and the length of that array
void bytequeue_init(byteQueue_t* queue, uint8_t* dataArray, byteQueueIndex_t arrayLen);
//add an item to the queue, returns false if the queue is full
bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item);
// add an item to the queue, returns false if the queue is full
bool bytequeue_enqueue(byteQueue_t* queue, uint8_t item);
//get the length of the queue
byteQueueIndex_t bytequeue_length(byteQueue_t * queue);
// get the length of the queue
byteQueueIndex_t bytequeue_length(byteQueue_t* queue);
//this grabs data at the index given [starting at queue->start]
uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index);
// this grabs data at the index given [starting at queue->start]
uint8_t bytequeue_get(byteQueue_t* queue, byteQueueIndex_t index);
//update the index in the queue to reflect data that has been dealt with
void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove);
// update the index in the queue to reflect data that has been dealt with
void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove);
#ifdef __cplusplus
}
#endif
#endif
#endif

54
tmk_core/protocol/midi/bytequeue/interrupt_setting.c Executable file → Normal file
View file

@ -1,49 +1,43 @@
//Copyright 20010 Alex Norman
//writen by Alex Norman
// Copyright 20010 Alex Norman
// writen by Alex Norman
//
//This file is part of avr-bytequeue.
// This file is part of avr-bytequeue.
//
//avr-bytequeue is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-bytequeue is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-bytequeue is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-bytequeue is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
//AVR specific code
//should be able to port to other systems by simply providing chip specific
//implementations of the typedef and these functions
// AVR specific code
// should be able to port to other systems by simply providing chip specific
// implementations of the typedef and these functions
#include "interrupt_setting.h"
#if defined(__AVR__)
#include <avr/interrupt.h>
# include <avr/interrupt.h>
interrupt_setting_t store_and_clear_interrupt(void) {
uint8_t sreg = SREG;
cli();
return sreg;
uint8_t sreg = SREG;
cli();
return sreg;
}
void restore_interrupt_setting(interrupt_setting_t setting) {
SREG = setting;
}
void restore_interrupt_setting(interrupt_setting_t setting) { SREG = setting; }
#elif defined(__arm__)
#include "ch.h"
# include "ch.h"
interrupt_setting_t store_and_clear_interrupt(void) {
chSysLock();
return 0;
chSysLock();
return 0;
}
void restore_interrupt_setting(interrupt_setting_t setting) {
chSysUnlock();
}
void restore_interrupt_setting(interrupt_setting_t setting) { chSysUnlock(); }
#endif

33
tmk_core/protocol/midi/bytequeue/interrupt_setting.h Executable file → Normal file
View file

@ -1,39 +1,38 @@
//Copyright 20010 Alex Norman
//writen by Alex Norman
// Copyright 20010 Alex Norman
// writen by Alex Norman
//
//This file is part of avr-bytequeue.
// This file is part of avr-bytequeue.
//
//avr-bytequeue is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-bytequeue is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-bytequeue is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-bytequeue is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>.
#ifndef INTERRUPT_SETTING_H
#define INTERRUPT_SETTING_H
#ifdef __cplusplus
extern "C" {
#endif
#endif
#include <inttypes.h>
//AVR specific typedef
// AVR specific typedef
typedef uint8_t interrupt_setting_t;
interrupt_setting_t store_and_clear_interrupt(void);
void restore_interrupt_setting(interrupt_setting_t setting);
void restore_interrupt_setting(interrupt_setting_t setting);
#ifdef __cplusplus
}
#endif
#endif
#endif

378
tmk_core/protocol/midi/midi.c Executable file → Normal file
View file

@ -1,277 +1,181 @@
//midi for embedded chips,
//Copyright 2010 Alex Norman
// midi for embedded chips,
// Copyright 2010 Alex Norman
//
//This file is part of avr-midi.
// This file is part of avr-midi.
//
//avr-midi is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-midi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-midi is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-midi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
#include "midi.h"
#include <string.h> //for memcpy
#include <string.h> //for memcpy
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#ifndef NULL
#define NULL 0
# define NULL 0
#endif
bool midi_is_statusbyte(uint8_t theByte){
return (bool)(theByte & MIDI_STATUSMASK);
bool midi_is_statusbyte(uint8_t theByte) { return (bool)(theByte & MIDI_STATUSMASK); }
bool midi_is_realtime(uint8_t theByte) { return (theByte >= MIDI_CLOCK); }
midi_packet_length_t midi_packet_length(uint8_t status) {
switch (status & 0xF0) {
case MIDI_CC:
case MIDI_NOTEON:
case MIDI_NOTEOFF:
case MIDI_AFTERTOUCH:
case MIDI_PITCHBEND:
return THREE;
case MIDI_PROGCHANGE:
case MIDI_CHANPRESSURE:
case MIDI_SONGSELECT:
return TWO;
case 0xF0:
switch (status) {
case MIDI_CLOCK:
case MIDI_TICK:
case MIDI_START:
case MIDI_CONTINUE:
case MIDI_STOP:
case MIDI_ACTIVESENSE:
case MIDI_RESET:
case MIDI_TUNEREQUEST:
return ONE;
case MIDI_SONGPOSITION:
return THREE;
case MIDI_TC_QUARTERFRAME:
case MIDI_SONGSELECT:
return TWO;
case SYSEX_END:
case SYSEX_BEGIN:
default:
return UNDEFINED;
}
default:
return UNDEFINED;
}
}
bool midi_is_realtime(uint8_t theByte){
return (theByte >= MIDI_CLOCK);
void midi_send_cc(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t val) {
// CC Status: 0xB0 to 0xBF where the low nibble is the MIDI channel.
// CC Data: Controller Num, Controller Val
device->send_func(device, 3, MIDI_CC | (chan & MIDI_CHANMASK), num & 0x7F, val & 0x7F);
}
midi_packet_length_t midi_packet_length(uint8_t status){
switch(status & 0xF0){
case MIDI_CC:
case MIDI_NOTEON:
case MIDI_NOTEOFF:
case MIDI_AFTERTOUCH:
case MIDI_PITCHBEND:
return THREE;
case MIDI_PROGCHANGE:
case MIDI_CHANPRESSURE:
case MIDI_SONGSELECT:
return TWO;
case 0xF0:
switch(status) {
case MIDI_CLOCK:
case MIDI_TICK:
case MIDI_START:
case MIDI_CONTINUE:
case MIDI_STOP:
case MIDI_ACTIVESENSE:
case MIDI_RESET:
case MIDI_TUNEREQUEST:
return ONE;
case MIDI_SONGPOSITION:
return THREE;
case MIDI_TC_QUARTERFRAME:
case MIDI_SONGSELECT:
return TWO;
case SYSEX_END:
case SYSEX_BEGIN:
default:
return UNDEFINED;
}
default:
return UNDEFINED;
}
void midi_send_noteon(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel) {
// Note Data: Note Num, Note Velocity
device->send_func(device, 3, MIDI_NOTEON | (chan & MIDI_CHANMASK), num & 0x7F, vel & 0x7F);
}
void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val){
//CC Status: 0xB0 to 0xBF where the low nibble is the MIDI channel.
//CC Data: Controller Num, Controller Val
device->send_func(device, 3,
MIDI_CC | (chan & MIDI_CHANMASK),
num & 0x7F,
val & 0x7F);
void midi_send_noteoff(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel) {
// Note Data: Note Num, Note Velocity
device->send_func(device, 3, MIDI_NOTEOFF | (chan & MIDI_CHANMASK), num & 0x7F, vel & 0x7F);
}
void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel){
//Note Data: Note Num, Note Velocity
device->send_func(device, 3,
MIDI_NOTEON | (chan & MIDI_CHANMASK),
num & 0x7F,
vel & 0x7F);
void midi_send_aftertouch(MidiDevice* device, uint8_t chan, uint8_t note_num, uint8_t amt) { device->send_func(device, 3, MIDI_AFTERTOUCH | (chan & MIDI_CHANMASK), note_num & 0x7F, amt & 0x7F); }
// XXX does this work right?
// amt in range -0x2000, 0x1fff
// uAmt should be in range..
// 0x0000 to 0x3FFF
void midi_send_pitchbend(MidiDevice* device, uint8_t chan, int16_t amt) {
uint16_t uAmt;
// check range
if (amt > 0x1fff) {
uAmt = 0x3FFF;
} else if (amt < -0x2000) {
uAmt = 0;
} else {
uAmt = amt + 0x2000;
}
device->send_func(device, 3, MIDI_PITCHBEND | (chan & MIDI_CHANMASK), uAmt & 0x7F, (uAmt >> 7) & 0x7F);
}
void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel){
//Note Data: Note Num, Note Velocity
device->send_func(device, 3,
MIDI_NOTEOFF | (chan & MIDI_CHANMASK),
num & 0x7F,
vel & 0x7F);
void midi_send_programchange(MidiDevice* device, uint8_t chan, uint8_t num) { device->send_func(device, 2, MIDI_PROGCHANGE | (chan & MIDI_CHANMASK), num & 0x7F, 0); }
void midi_send_channelpressure(MidiDevice* device, uint8_t chan, uint8_t amt) { device->send_func(device, 2, MIDI_CHANPRESSURE | (chan & MIDI_CHANMASK), amt & 0x7F, 0); }
void midi_send_clock(MidiDevice* device) { device->send_func(device, 1, MIDI_CLOCK, 0, 0); }
void midi_send_tick(MidiDevice* device) { device->send_func(device, 1, MIDI_TICK, 0, 0); }
void midi_send_start(MidiDevice* device) { device->send_func(device, 1, MIDI_START, 0, 0); }
void midi_send_continue(MidiDevice* device) { device->send_func(device, 1, MIDI_CONTINUE, 0, 0); }
void midi_send_stop(MidiDevice* device) { device->send_func(device, 1, MIDI_STOP, 0, 0); }
void midi_send_activesense(MidiDevice* device) { device->send_func(device, 1, MIDI_ACTIVESENSE, 0, 0); }
void midi_send_reset(MidiDevice* device) { device->send_func(device, 1, MIDI_RESET, 0, 0); }
void midi_send_tcquarterframe(MidiDevice* device, uint8_t time) { device->send_func(device, 2, MIDI_TC_QUARTERFRAME, time & 0x7F, 0); }
// XXX is this right?
void midi_send_songposition(MidiDevice* device, uint16_t pos) { device->send_func(device, 3, MIDI_SONGPOSITION, pos & 0x7F, (pos >> 7) & 0x7F); }
void midi_send_songselect(MidiDevice* device, uint8_t song) { device->send_func(device, 2, MIDI_SONGSELECT, song & 0x7F, 0); }
void midi_send_tunerequest(MidiDevice* device) { device->send_func(device, 1, MIDI_TUNEREQUEST, 0, 0); }
void midi_send_byte(MidiDevice* device, uint8_t b) { device->send_func(device, 1, b, 0, 0); }
void midi_send_data(MidiDevice* device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
// ensure that the count passed along is always 3 or lower
if (count > 3) {
// TODO how to do this correctly?
}
device->send_func(device, count, byte0, byte1, byte2);
}
void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, uint8_t amt){
device->send_func(device, 3,
MIDI_AFTERTOUCH | (chan & MIDI_CHANMASK),
note_num & 0x7F,
amt & 0x7F);
void midi_send_array(MidiDevice* device, uint16_t count, uint8_t* array) {
uint16_t i;
for (i = 0; i < count; i += 3) {
uint8_t b[3] = {0, 0, 0};
uint16_t to_send = count - i;
to_send = (to_send > 3) ? 3 : to_send;
memcpy(b, array + i, to_send);
midi_send_data(device, to_send, b[0], b[1], b[2]);
}
}
//XXX does this work right?
//amt in range -0x2000, 0x1fff
//uAmt should be in range..
//0x0000 to 0x3FFF
void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt){
uint16_t uAmt;
//check range
if(amt > 0x1fff){
uAmt = 0x3FFF;
} else if(amt < -0x2000){
uAmt = 0;
} else {
uAmt = amt + 0x2000;
}
device->send_func(device, 3,
MIDI_PITCHBEND | (chan & MIDI_CHANMASK),
uAmt & 0x7F,
(uAmt >> 7) & 0x7F);
}
void midi_register_cc_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_cc_callback = func; }
void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num){
device->send_func(device, 2,
MIDI_PROGCHANGE | (chan & MIDI_CHANMASK),
num & 0x7F,
0);
}
void midi_register_noteon_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_noteon_callback = func; }
void midi_send_channelpressure(MidiDevice * device, uint8_t chan, uint8_t amt){
device->send_func(device, 2,
MIDI_CHANPRESSURE | (chan & MIDI_CHANMASK),
amt & 0x7F,
0);
}
void midi_register_noteoff_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_noteoff_callback = func; }
void midi_send_clock(MidiDevice * device){
device->send_func(device, 1, MIDI_CLOCK, 0, 0);
}
void midi_register_aftertouch_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_aftertouch_callback = func; }
void midi_send_tick(MidiDevice * device){
device->send_func(device, 1, MIDI_TICK, 0, 0);
}
void midi_register_pitchbend_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_pitchbend_callback = func; }
void midi_send_start(MidiDevice * device){
device->send_func(device, 1, MIDI_START, 0, 0);
}
void midi_register_songposition_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_songposition_callback = func; }
void midi_send_continue(MidiDevice * device){
device->send_func(device, 1, MIDI_CONTINUE, 0, 0);
}
void midi_register_progchange_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_progchange_callback = func; }
void midi_send_stop(MidiDevice * device){
device->send_func(device, 1, MIDI_STOP, 0, 0);
}
void midi_register_chanpressure_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_chanpressure_callback = func; }
void midi_send_activesense(MidiDevice * device){
device->send_func(device, 1, MIDI_ACTIVESENSE, 0, 0);
}
void midi_register_songselect_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_songselect_callback = func; }
void midi_send_reset(MidiDevice * device){
device->send_func(device, 1, MIDI_RESET, 0, 0);
}
void midi_register_tc_quarterframe_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_tc_quarterframe_callback = func; }
void midi_send_tcquarterframe(MidiDevice * device, uint8_t time){
device->send_func(device, 2,
MIDI_TC_QUARTERFRAME,
time & 0x7F,
0);
}
void midi_register_realtime_callback(MidiDevice* device, midi_one_byte_func_t func) { device->input_realtime_callback = func; }
//XXX is this right?
void midi_send_songposition(MidiDevice * device, uint16_t pos){
device->send_func(device, 3,
MIDI_SONGPOSITION,
pos & 0x7F,
(pos >> 7) & 0x7F);
}
void midi_register_tunerequest_callback(MidiDevice* device, midi_one_byte_func_t func) { device->input_tunerequest_callback = func; }
void midi_send_songselect(MidiDevice * device, uint8_t song){
device->send_func(device, 2,
MIDI_SONGSELECT,
song & 0x7F,
0);
}
void midi_register_sysex_callback(MidiDevice* device, midi_sysex_func_t func) { device->input_sysex_callback = func; }
void midi_send_tunerequest(MidiDevice * device){
device->send_func(device, 1, MIDI_TUNEREQUEST, 0, 0);
}
void midi_send_byte(MidiDevice * device, uint8_t b){
device->send_func(device, 1, b, 0, 0);
}
void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2){
//ensure that the count passed along is always 3 or lower
if (count > 3) {
//TODO how to do this correctly?
}
device->send_func(device, count, byte0, byte1, byte2);
}
void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array) {
uint16_t i;
for (i = 0; i < count; i += 3) {
uint8_t b[3] = { 0, 0, 0 };
uint16_t to_send = count - i;
to_send = (to_send > 3) ? 3 : to_send;
memcpy(b, array + i, to_send);
midi_send_data(device, to_send, b[0], b[1], b[2]);
}
}
void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func){
device->input_cc_callback = func;
}
void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t func){
device->input_noteon_callback = func;
}
void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t func){
device->input_noteoff_callback = func;
}
void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func_t func){
device->input_aftertouch_callback = func;
}
void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_t func){
device->input_pitchbend_callback = func;
}
void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_func_t func){
device->input_songposition_callback = func;
}
void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t func) {
device->input_progchange_callback = func;
}
void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func_t func) {
device->input_chanpressure_callback = func;
}
void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t func) {
device->input_songselect_callback = func;
}
void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_func_t func) {
device->input_tc_quarterframe_callback = func;
}
void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t func){
device->input_realtime_callback = func;
}
void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_t func){
device->input_tunerequest_callback = func;
}
void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func) {
device->input_sysex_callback = func;
}
void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_t func){
device->input_fallthrough_callback = func;
}
void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t func){
device->input_catchall_callback = func;
}
void midi_register_fallthrough_callback(MidiDevice* device, midi_var_byte_func_t func) { device->input_fallthrough_callback = func; }
void midi_register_catchall_callback(MidiDevice* device, midi_var_byte_func_t func) { device->input_catchall_callback = func; }

152
tmk_core/protocol/midi/midi.h Executable file → Normal file
View file

@ -1,20 +1,20 @@
//midi for embedded chips,
//Copyright 2010 Alex Norman
// midi for embedded chips,
// Copyright 2010 Alex Norman
//
//This file is part of avr-midi.
// This file is part of avr-midi.
//
//avr-midi is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-midi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-midi is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-midi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
/**
* @file
@ -30,7 +30,7 @@
#ifdef __cplusplus
extern "C" {
#endif
#endif
#include "midi_device.h"
#include "midi_function_types.h"
@ -48,8 +48,8 @@ extern "C" {
* You must call this before using the device in question.
*
* @param device the device to initialize
*/
void midi_device_init(MidiDevice * device); // [implementation in midi_device.c]
*/
void midi_device_init(MidiDevice* device); // [implementation in midi_device.c]
/**
* @brief Process input data
@ -58,8 +58,8 @@ void midi_device_init(MidiDevice * device); // [implementation in midi_device.c]
* if you expect to have your input callbacks called.
*
* @param device the device to process
*/
void midi_device_process(MidiDevice * device); // [implementation in midi_device.c]
*/
void midi_device_process(MidiDevice* device); // [implementation in midi_device.c]
/**@}*/
@ -76,8 +76,8 @@ void midi_device_process(MidiDevice * device); // [implementation in midi_device
* @param chan the channel to send on, 0-15
* @param num the cc num
* @param val the value of that cc num
*/
void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val);
*/
void midi_send_cc(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t val);
/**
* @brief Send a note on message via the given device.
@ -86,8 +86,8 @@ void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val);
* @param chan the channel to send on, 0-15
* @param num the note number
* @param vel the note velocity
*/
void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel);
*/
void midi_send_noteon(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel);
/**
* @brief Send a note off message via the given device.
@ -96,8 +96,8 @@ void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t ve
* @param chan the channel to send on, 0-15
* @param num the note number
* @param vel the note velocity
*/
void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel);
*/
void midi_send_noteoff(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel);
/**
* @brief Send an after touch message via the given device.
@ -106,8 +106,8 @@ void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t v
* @param chan the channel to send on, 0-15
* @param note_num the note number
* @param amt the after touch amount
*/
void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, uint8_t amt);
*/
void midi_send_aftertouch(MidiDevice* device, uint8_t chan, uint8_t note_num, uint8_t amt);
/**
* @brief Send a pitch bend message via the given device.
@ -115,8 +115,8 @@ void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, u
* @param device the device to use for sending
* @param chan the channel to send on, 0-15
* @param amt the bend amount range: -8192..8191, 0 means no bend
*/
void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt); //range -8192, 8191
*/
void midi_send_pitchbend(MidiDevice* device, uint8_t chan, int16_t amt); // range -8192, 8191
/**
* @brief Send a program change message via the given device.
@ -124,8 +124,8 @@ void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt); //rang
* @param device the device to use for sending
* @param chan the channel to send on, 0-15
* @param num the program to change to
*/
void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num);
*/
void midi_send_programchange(MidiDevice* device, uint8_t chan, uint8_t num);
/**
* @brief Send a channel pressure message via the given device.
@ -133,58 +133,57 @@ void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num);
* @param device the device to use for sending
* @param chan the channel to send on, 0-15
* @param amt the amount of channel pressure
*/
void midi_send_channelpressure(MidiDevice * device, uint8_t chan, uint8_t amt);
*/
void midi_send_channelpressure(MidiDevice* device, uint8_t chan, uint8_t amt);
/**
* @brief Send a clock message via the given device.
*
* @param device the device to use for sending
*/
void midi_send_clock(MidiDevice * device);
void midi_send_clock(MidiDevice* device);
/**
* @brief Send a tick message via the given device.
*
* @param device the device to use for sending
*/
void midi_send_tick(MidiDevice * device);
void midi_send_tick(MidiDevice* device);
/**
* @brief Send a start message via the given device.
*
* @param device the device to use for sending
*/
void midi_send_start(MidiDevice * device);
void midi_send_start(MidiDevice* device);
/**
* @brief Send a continue message via the given device.
*
* @param device the device to use for sending
*/
void midi_send_continue(MidiDevice * device);
void midi_send_continue(MidiDevice* device);
/**
* @brief Send a stop message via the given device.
*
* @param device the device to use for sending
*/
void midi_send_stop(MidiDevice * device);
void midi_send_stop(MidiDevice* device);
/**
* @brief Send an active sense message via the given device.
*
* @param device the device to use for sending
*/
void midi_send_activesense(MidiDevice * device);
void midi_send_activesense(MidiDevice* device);
/**
* @brief Send a reset message via the given device.
*
* @param device the device to use for sending
*/
void midi_send_reset(MidiDevice * device);
void midi_send_reset(MidiDevice* device);
/**
* @brief Send a tc quarter frame message via the given device.
@ -192,7 +191,7 @@ void midi_send_reset(MidiDevice * device);
* @param device the device to use for sending
* @param time the time of this quarter frame, range 0..16383
*/
void midi_send_tcquarterframe(MidiDevice * device, uint8_t time);
void midi_send_tcquarterframe(MidiDevice* device, uint8_t time);
/**
* @brief Send a song position message via the given device.
@ -200,7 +199,7 @@ void midi_send_tcquarterframe(MidiDevice * device, uint8_t time);
* @param device the device to use for sending
* @param pos the song position
*/
void midi_send_songposition(MidiDevice * device, uint16_t pos);
void midi_send_songposition(MidiDevice* device, uint16_t pos);
/**
* @brief Send a song select message via the given device.
@ -208,14 +207,14 @@ void midi_send_songposition(MidiDevice * device, uint16_t pos);
* @param device the device to use for sending
* @param song the song to select
*/
void midi_send_songselect(MidiDevice * device, uint8_t song);
void midi_send_songselect(MidiDevice* device, uint8_t song);
/**
* @brief Send a tune request message via the given device.
*
* @param device the device to use for sending
*/
void midi_send_tunerequest(MidiDevice * device);
void midi_send_tunerequest(MidiDevice* device);
/**
* @brief Send a byte via the given device.
@ -228,7 +227,7 @@ void midi_send_tunerequest(MidiDevice * device);
* @param device the device to use for sending
* @param b the byte to send
*/
void midi_send_byte(MidiDevice * device, uint8_t b);
void midi_send_byte(MidiDevice* device, uint8_t b);
/**
* @brief Send up to 3 bytes of data
@ -241,7 +240,7 @@ void midi_send_byte(MidiDevice * device, uint8_t b);
* @param byte1 the second byte, ignored if cnt % 4 != 2
* @param byte2 the third byte, ignored if cnt % 4 != 3
*/
void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2);
void midi_send_data(MidiDevice* device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2);
/**
* @brief Send an array of formatted midi data.
@ -252,14 +251,13 @@ void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t
* @param count the count of bytes to send
* @param array the array of bytes
*/
void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array);
void midi_send_array(MidiDevice* device, uint16_t count, uint8_t* array);
/**@}*/
/**
* @defgroup input_callback_reg Input callback registration functions
*
*
* @brief These are the functions you use to register your input callbacks.
*
* The functions are called when the appropriate midi message is matched on the
@ -268,7 +266,7 @@ void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array);
* @{
*/
//three byte funcs
// three byte funcs
/**
* @brief Register a control change message (cc) callback.
@ -276,7 +274,7 @@ void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array);
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func);
void midi_register_cc_callback(MidiDevice* device, midi_three_byte_func_t func);
/**
* @brief Register a note on callback.
@ -284,7 +282,7 @@ void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func)
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t func);
void midi_register_noteon_callback(MidiDevice* device, midi_three_byte_func_t func);
/**
* @brief Register a note off callback.
@ -292,7 +290,7 @@ void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t f
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t func);
void midi_register_noteoff_callback(MidiDevice* device, midi_three_byte_func_t func);
/**
* @brief Register an after touch callback.
@ -301,7 +299,7 @@ void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t
* @param func the callback function to register
*/
void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func_t func);
void midi_register_aftertouch_callback(MidiDevice* device, midi_three_byte_func_t func);
/**
* @brief Register a pitch bend callback.
@ -309,7 +307,7 @@ void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_t func);
void midi_register_pitchbend_callback(MidiDevice* device, midi_three_byte_func_t func);
/**
* @brief Register a song position callback.
@ -317,9 +315,9 @@ void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_func_t func);
void midi_register_songposition_callback(MidiDevice* device, midi_three_byte_func_t func);
//two byte funcs
// two byte funcs
/**
* @brief Register a program change callback.
@ -327,7 +325,7 @@ void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_fu
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t func);
void midi_register_progchange_callback(MidiDevice* device, midi_two_byte_func_t func);
/**
* @brief Register a channel pressure callback.
@ -335,7 +333,7 @@ void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func_t func);
void midi_register_chanpressure_callback(MidiDevice* device, midi_two_byte_func_t func);
/**
* @brief Register a song select callback.
@ -343,7 +341,7 @@ void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t func);
void midi_register_songselect_callback(MidiDevice* device, midi_two_byte_func_t func);
/**
* @brief Register a tc quarter frame callback.
@ -351,9 +349,9 @@ void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_func_t func);
void midi_register_tc_quarterframe_callback(MidiDevice* device, midi_two_byte_func_t func);
//one byte funcs
// one byte funcs
/**
* @brief Register a realtime callback.
@ -363,7 +361,7 @@ void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_f
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t func);
void midi_register_realtime_callback(MidiDevice* device, midi_one_byte_func_t func);
/**
* @brief Register a tune request callback.
@ -371,7 +369,7 @@ void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t f
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_t func);
void midi_register_tunerequest_callback(MidiDevice* device, midi_one_byte_func_t func);
/**
* @brief Register a sysex callback.
@ -379,7 +377,7 @@ void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func);
void midi_register_sysex_callback(MidiDevice* device, midi_sysex_func_t func);
/**
* @brief Register fall through callback.
@ -391,8 +389,7 @@ void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func);
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_t func);
void midi_register_fallthrough_callback(MidiDevice* device, midi_var_byte_func_t func);
/**
* @brief Register a catch all callback.
@ -403,7 +400,7 @@ void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_
* @param device the device associate with
* @param func the callback function to register
*/
void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t func);
void midi_register_catchall_callback(MidiDevice* device, midi_var_byte_func_t func);
/**@}*/
@ -417,11 +414,7 @@ void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t f
*
* An enumeration of the possible packet length values.
*/
typedef enum {
UNDEFINED = 0,
ONE = 1,
TWO = 2,
THREE = 3} midi_packet_length_t;
typedef enum { UNDEFINED = 0, ONE = 1, TWO = 2, THREE = 3 } midi_packet_length_t;
/**
* @brief Test to see if the byte given is a status byte
@ -456,11 +449,11 @@ midi_packet_length_t midi_packet_length(uint8_t status);
#define SYSEX_BEGIN 0xF0
#define SYSEX_END 0xF7
//if you and this with a byte and you get anything non-zero
//it is a status message
// if you and this with a byte and you get anything non-zero
// it is a status message
#define MIDI_STATUSMASK 0x80
//if you and this with a status message that contains channel info,
//you'll get the channel
// if you and this with a status message that contains channel info,
// you'll get the channel
#define MIDI_CHANMASK 0x0F
#define MIDI_CC 0xB0
@ -471,7 +464,7 @@ midi_packet_length_t midi_packet_length(uint8_t status);
#define MIDI_PROGCHANGE 0xC0
#define MIDI_CHANPRESSURE 0xD0
//midi realtime
// midi realtime
#define MIDI_CLOCK 0xF8
#define MIDI_TICK 0xF9
#define MIDI_START 0xFA
@ -485,14 +478,13 @@ midi_packet_length_t midi_packet_length(uint8_t status);
#define MIDI_SONGSELECT 0xF3
#define MIDI_TUNEREQUEST 0xF6
//This ID is for educational or development use only
// This ID is for educational or development use only
#define SYSEX_EDUMANUFID 0x7D
/**@}*/
#ifdef __cplusplus
}
#endif
#endif
#endif

483
tmk_core/protocol/midi/midi_device.c Executable file → Normal file
View file

@ -1,291 +1,272 @@
//midi for embedded chips,
//Copyright 2010 Alex Norman
// midi for embedded chips,
// Copyright 2010 Alex Norman
//
//This file is part of avr-midi.
// This file is part of avr-midi.
//
//avr-midi is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-midi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-midi is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-midi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
#include "midi_device.h"
#include "midi.h"
#ifndef NULL
#define NULL 0
# define NULL 0
#endif
//forward declarations, internally used to call the callbacks
void midi_input_callbacks(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2);
void midi_process_byte(MidiDevice * device, uint8_t input);
// forward declarations, internally used to call the callbacks
void midi_input_callbacks(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2);
void midi_process_byte(MidiDevice* device, uint8_t input);
void midi_device_init(MidiDevice * device){
device->input_state = IDLE;
device->input_count = 0;
bytequeue_init(&device->input_queue, device->input_queue_data, MIDI_INPUT_QUEUE_LENGTH);
void midi_device_init(MidiDevice* device) {
device->input_state = IDLE;
device->input_count = 0;
bytequeue_init(&device->input_queue, device->input_queue_data, MIDI_INPUT_QUEUE_LENGTH);
//three byte funcs
device->input_cc_callback = NULL;
device->input_noteon_callback = NULL;
device->input_noteoff_callback = NULL;
device->input_aftertouch_callback = NULL;
device->input_pitchbend_callback = NULL;
device->input_songposition_callback = NULL;
// three byte funcs
device->input_cc_callback = NULL;
device->input_noteon_callback = NULL;
device->input_noteoff_callback = NULL;
device->input_aftertouch_callback = NULL;
device->input_pitchbend_callback = NULL;
device->input_songposition_callback = NULL;
//two byte funcs
device->input_progchange_callback = NULL;
device->input_chanpressure_callback = NULL;
device->input_songselect_callback = NULL;
device->input_tc_quarterframe_callback = NULL;
// two byte funcs
device->input_progchange_callback = NULL;
device->input_chanpressure_callback = NULL;
device->input_songselect_callback = NULL;
device->input_tc_quarterframe_callback = NULL;
//one byte funcs
device->input_realtime_callback = NULL;
device->input_tunerequest_callback = NULL;
// one byte funcs
device->input_realtime_callback = NULL;
device->input_tunerequest_callback = NULL;
//var byte functions
device->input_sysex_callback = NULL;
device->input_fallthrough_callback = NULL;
device->input_catchall_callback = NULL;
// var byte functions
device->input_sysex_callback = NULL;
device->input_fallthrough_callback = NULL;
device->input_catchall_callback = NULL;
device->pre_input_process_callback = NULL;
device->pre_input_process_callback = NULL;
}
void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input) {
uint8_t i;
for (i = 0; i < cnt; i++)
bytequeue_enqueue(&device->input_queue, input[i]);
void midi_device_input(MidiDevice* device, uint8_t cnt, uint8_t* input) {
uint8_t i;
for (i = 0; i < cnt; i++) bytequeue_enqueue(&device->input_queue, input[i]);
}
void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_func){
device->send_func = send_func;
}
void midi_device_set_send_func(MidiDevice* device, midi_var_byte_func_t send_func) { device->send_func = send_func; }
void midi_device_set_pre_input_process_func(MidiDevice * device, midi_no_byte_func_t pre_process_func){
device->pre_input_process_callback = pre_process_func;
}
void midi_device_set_pre_input_process_func(MidiDevice* device, midi_no_byte_func_t pre_process_func) { device->pre_input_process_callback = pre_process_func; }
void midi_device_process(MidiDevice * device) {
//call the pre_input_process_callback if there is one
if(device->pre_input_process_callback)
device->pre_input_process_callback(device);
void midi_device_process(MidiDevice* device) {
// call the pre_input_process_callback if there is one
if (device->pre_input_process_callback) device->pre_input_process_callback(device);
//pull stuff off the queue and process
byteQueueIndex_t len = bytequeue_length(&device->input_queue);
uint16_t i;
//TODO limit number of bytes processed?
for(i = 0; i < len; i++) {
uint8_t val = bytequeue_get(&device->input_queue, 0);
midi_process_byte(device, val);
bytequeue_remove(&device->input_queue, 1);
}
}
void midi_process_byte(MidiDevice * device, uint8_t input) {
if (midi_is_realtime(input)) {
//call callback, store and restore state
input_state_t state = device->input_state;
device->input_state = ONE_BYTE_MESSAGE;
midi_input_callbacks(device, 1, input, 0, 0);
device->input_state = state;
} else if (midi_is_statusbyte(input)) {
//store the byte
if (device->input_state != SYSEX_MESSAGE) {
device->input_buffer[0] = input;
device->input_count = 1;
// pull stuff off the queue and process
byteQueueIndex_t len = bytequeue_length(&device->input_queue);
uint16_t i;
// TODO limit number of bytes processed?
for (i = 0; i < len; i++) {
uint8_t val = bytequeue_get(&device->input_queue, 0);
midi_process_byte(device, val);
bytequeue_remove(&device->input_queue, 1);
}
switch (midi_packet_length(input)) {
case ONE:
device->input_state = ONE_BYTE_MESSAGE;;
}
void midi_process_byte(MidiDevice* device, uint8_t input) {
if (midi_is_realtime(input)) {
// call callback, store and restore state
input_state_t state = device->input_state;
device->input_state = ONE_BYTE_MESSAGE;
midi_input_callbacks(device, 1, input, 0, 0);
device->input_state = IDLE;
break;
case TWO:
device->input_state = TWO_BYTE_MESSAGE;
break;
case THREE:
device->input_state = THREE_BYTE_MESSAGE;
break;
case UNDEFINED:
switch(input) {
case SYSEX_BEGIN:
device->input_state = SYSEX_MESSAGE;
device->input_state = state;
} else if (midi_is_statusbyte(input)) {
// store the byte
if (device->input_state != SYSEX_MESSAGE) {
device->input_buffer[0] = input;
device->input_count = 1;
break;
case SYSEX_END:
//send what is left in the input buffer, set idle
device->input_count = 1;
}
switch (midi_packet_length(input)) {
case ONE:
device->input_state = ONE_BYTE_MESSAGE;
;
midi_input_callbacks(device, 1, input, 0, 0);
device->input_state = IDLE;
break;
case TWO:
device->input_state = TWO_BYTE_MESSAGE;
break;
case THREE:
device->input_state = THREE_BYTE_MESSAGE;
break;
case UNDEFINED:
switch (input) {
case SYSEX_BEGIN:
device->input_state = SYSEX_MESSAGE;
device->input_buffer[0] = input;
device->input_count = 1;
break;
case SYSEX_END:
// send what is left in the input buffer, set idle
device->input_buffer[device->input_count % 3] = input;
device->input_count += 1;
// call the callback
midi_input_callbacks(device, device->input_count, device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
device->input_state = IDLE;
break;
default:
device->input_state = IDLE;
device->input_count = 0;
}
break;
default:
device->input_state = IDLE;
device->input_count = 0;
break;
}
} else {
if (device->input_state != IDLE) {
// store the byte
device->input_buffer[device->input_count % 3] = input;
// increment count
uint16_t prev = device->input_count;
device->input_count += 1;
//call the callback
midi_input_callbacks(device, device->input_count,
device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
device->input_state = IDLE;
break;
default:
device->input_state = IDLE;
device->input_count = 0;
}
break;
default:
device->input_state = IDLE;
device->input_count = 0;
break;
}
} else {
if (device->input_state != IDLE) {
//store the byte
device->input_buffer[device->input_count % 3] = input;
//increment count
uint16_t prev = device->input_count;
device->input_count += 1;
switch(prev % 3) {
case 2:
//call callback
midi_input_callbacks(device, device->input_count,
device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
if (device->input_state != SYSEX_MESSAGE) {
//set to 1, keeping status byte, allowing for running status
device->input_count = 1;
}
break;
case 1:
if (device->input_state == TWO_BYTE_MESSAGE) {
//call callback
midi_input_callbacks(device, device->input_count,
device->input_buffer[0], device->input_buffer[1], 0);
if (device->input_state != SYSEX_MESSAGE) {
//set to 1, keeping status byte, allowing for running status
device->input_count = 1;
switch (prev % 3) {
case 2:
// call callback
midi_input_callbacks(device, device->input_count, device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]);
if (device->input_state != SYSEX_MESSAGE) {
// set to 1, keeping status byte, allowing for running status
device->input_count = 1;
}
break;
case 1:
if (device->input_state == TWO_BYTE_MESSAGE) {
// call callback
midi_input_callbacks(device, device->input_count, device->input_buffer[0], device->input_buffer[1], 0);
if (device->input_state != SYSEX_MESSAGE) {
// set to 1, keeping status byte, allowing for running status
device->input_count = 1;
}
}
break;
case 0:
default:
// one byte messages are dealt with directly
break;
}
}
break;
case 0:
default:
//one byte messages are dealt with directly
break;
}
}
}
}
}
void midi_input_callbacks(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
//did we end up calling a callback?
bool called = false;
if (device->input_state == SYSEX_MESSAGE) {
if (device->input_sysex_callback) {
const uint16_t start = ((cnt - 1) / 3) * 3;
const uint8_t length = (cnt - start);
uint8_t data[3];
data[0] = byte0;
data[1] = byte1;
data[2] = byte2;
device->input_sysex_callback(device, start, length, data);
called = true;
}
} else {
switch (cnt) {
case 3:
{
midi_three_byte_func_t func = NULL;
switch (byte0 & 0xF0) {
case MIDI_CC:
func = device->input_cc_callback;
break;
case MIDI_NOTEON:
func = device->input_noteon_callback;
break;
case MIDI_NOTEOFF:
func = device->input_noteoff_callback;
break;
case MIDI_AFTERTOUCH:
func = device->input_aftertouch_callback;
break;
case MIDI_PITCHBEND:
func = device->input_pitchbend_callback;
break;
case 0xF0:
if (byte0 == MIDI_SONGPOSITION)
func = device->input_songposition_callback;
break;
void midi_input_callbacks(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
// did we end up calling a callback?
bool called = false;
if (device->input_state == SYSEX_MESSAGE) {
if (device->input_sysex_callback) {
const uint16_t start = ((cnt - 1) / 3) * 3;
const uint8_t length = (cnt - start);
uint8_t data[3];
data[0] = byte0;
data[1] = byte1;
data[2] = byte2;
device->input_sysex_callback(device, start, length, data);
called = true;
}
} else {
switch (cnt) {
case 3: {
midi_three_byte_func_t func = NULL;
switch (byte0 & 0xF0) {
case MIDI_CC:
func = device->input_cc_callback;
break;
case MIDI_NOTEON:
func = device->input_noteon_callback;
break;
case MIDI_NOTEOFF:
func = device->input_noteoff_callback;
break;
case MIDI_AFTERTOUCH:
func = device->input_aftertouch_callback;
break;
case MIDI_PITCHBEND:
func = device->input_pitchbend_callback;
break;
case 0xF0:
if (byte0 == MIDI_SONGPOSITION) func = device->input_songposition_callback;
break;
default:
break;
}
if (func) {
// mask off the channel for non song position functions
if (byte0 == MIDI_SONGPOSITION)
func(device, byte0, byte1, byte2);
else
func(device, byte0 & 0x0F, byte1, byte2);
called = true;
}
} break;
case 2: {
midi_two_byte_func_t func = NULL;
switch (byte0 & 0xF0) {
case MIDI_PROGCHANGE:
func = device->input_progchange_callback;
break;
case MIDI_CHANPRESSURE:
func = device->input_chanpressure_callback;
break;
case 0xF0:
if (byte0 == MIDI_SONGSELECT)
func = device->input_songselect_callback;
else if (byte0 == MIDI_TC_QUARTERFRAME)
func = device->input_tc_quarterframe_callback;
break;
default:
break;
}
if (func) {
// mask off the channel
if (byte0 == MIDI_SONGSELECT || byte0 == MIDI_TC_QUARTERFRAME)
func(device, byte0, byte1);
else
func(device, byte0 & 0x0F, byte1);
called = true;
}
} break;
case 1: {
midi_one_byte_func_t func = NULL;
if (midi_is_realtime(byte0))
func = device->input_realtime_callback;
else if (byte0 == MIDI_TUNEREQUEST)
func = device->input_tunerequest_callback;
if (func) {
func(device, byte0);
called = true;
}
} break;
default:
break;
}
if(func) {
//mask off the channel for non song position functions
if (byte0 == MIDI_SONGPOSITION)
func(device, byte0, byte1, byte2);
else
func(device, byte0 & 0x0F, byte1, byte2);
called = true;
}
// just in case
if (cnt > 3) cnt = 0;
break;
}
break;
case 2:
{
midi_two_byte_func_t func = NULL;
switch (byte0 & 0xF0) {
case MIDI_PROGCHANGE:
func = device->input_progchange_callback;
break;
case MIDI_CHANPRESSURE:
func = device->input_chanpressure_callback;
break;
case 0xF0:
if (byte0 == MIDI_SONGSELECT)
func = device->input_songselect_callback;
else if (byte0 == MIDI_TC_QUARTERFRAME)
func = device->input_tc_quarterframe_callback;
break;
default:
break;
}
if(func) {
//mask off the channel
if (byte0 == MIDI_SONGSELECT || byte0 == MIDI_TC_QUARTERFRAME)
func(device, byte0, byte1);
else
func(device, byte0 & 0x0F, byte1);
called = true;
}
}
break;
case 1:
{
midi_one_byte_func_t func = NULL;
if (midi_is_realtime(byte0))
func = device->input_realtime_callback;
else if (byte0 == MIDI_TUNEREQUEST)
func = device->input_tunerequest_callback;
if (func) {
func(device, byte0);
called = true;
}
}
break;
default:
//just in case
if (cnt > 3)
cnt = 0;
break;
}
}
//if there is fallthrough default callback and we haven't called a more specific one,
//call the fallthrough
if (!called && device->input_fallthrough_callback)
device->input_fallthrough_callback(device, cnt, byte0, byte1, byte2);
//always call the catch all if it exists
if (device->input_catchall_callback)
device->input_catchall_callback(device, cnt, byte0, byte1, byte2);
// if there is fallthrough default callback and we haven't called a more specific one,
// call the fallthrough
if (!called && device->input_fallthrough_callback) device->input_fallthrough_callback(device, cnt, byte0, byte1, byte2);
// always call the catch all if it exists
if (device->input_catchall_callback) device->input_catchall_callback(device, cnt, byte0, byte1, byte2);
}

109
tmk_core/protocol/midi/midi_device.h Executable file → Normal file
View file

@ -1,20 +1,20 @@
//midi for embedded chips,
//Copyright 2010 Alex Norman
// midi for embedded chips,
// Copyright 2010 Alex Norman
//
//This file is part of avr-midi.
// This file is part of avr-midi.
//
//avr-midi is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-midi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-midi is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-midi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
/**
* @file
@ -26,7 +26,7 @@
#ifdef __cplusplus
extern "C" {
#endif
#endif
/**
* @defgroup midi_device Functions used when implementing your own midi device.
@ -51,14 +51,9 @@ extern "C" {
#include "bytequeue/bytequeue.h"
#define MIDI_INPUT_QUEUE_LENGTH 192
typedef enum {
IDLE,
ONE_BYTE_MESSAGE = 1,
TWO_BYTE_MESSAGE = 2,
THREE_BYTE_MESSAGE = 3,
SYSEX_MESSAGE} input_state_t;
typedef enum { IDLE, ONE_BYTE_MESSAGE = 1, TWO_BYTE_MESSAGE = 2, THREE_BYTE_MESSAGE = 3, SYSEX_MESSAGE } input_state_t;
typedef void (* midi_no_byte_func_t)(MidiDevice * device);
typedef void (*midi_no_byte_func_t)(MidiDevice* device);
/**
* \struct _midi_device
@ -71,45 +66,45 @@ typedef void (* midi_no_byte_func_t)(MidiDevice * device);
* You should not need to modify this structure directly.
*/
struct _midi_device {
//output send function
midi_var_byte_func_t send_func;
// output send function
midi_var_byte_func_t send_func;
//********input callbacks
//three byte funcs
midi_three_byte_func_t input_cc_callback;
midi_three_byte_func_t input_noteon_callback;
midi_three_byte_func_t input_noteoff_callback;
midi_three_byte_func_t input_aftertouch_callback;
midi_three_byte_func_t input_pitchbend_callback;
midi_three_byte_func_t input_songposition_callback;
//two byte funcs
midi_two_byte_func_t input_progchange_callback;
midi_two_byte_func_t input_chanpressure_callback;
midi_two_byte_func_t input_songselect_callback;
midi_two_byte_func_t input_tc_quarterframe_callback;
//one byte funcs
midi_one_byte_func_t input_realtime_callback;
midi_one_byte_func_t input_tunerequest_callback;
//********input callbacks
// three byte funcs
midi_three_byte_func_t input_cc_callback;
midi_three_byte_func_t input_noteon_callback;
midi_three_byte_func_t input_noteoff_callback;
midi_three_byte_func_t input_aftertouch_callback;
midi_three_byte_func_t input_pitchbend_callback;
midi_three_byte_func_t input_songposition_callback;
// two byte funcs
midi_two_byte_func_t input_progchange_callback;
midi_two_byte_func_t input_chanpressure_callback;
midi_two_byte_func_t input_songselect_callback;
midi_two_byte_func_t input_tc_quarterframe_callback;
// one byte funcs
midi_one_byte_func_t input_realtime_callback;
midi_one_byte_func_t input_tunerequest_callback;
//sysex
midi_sysex_func_t input_sysex_callback;
// sysex
midi_sysex_func_t input_sysex_callback;
//only called if more specific callback is not matched
midi_var_byte_func_t input_fallthrough_callback;
//called if registered, independent of other callbacks
midi_var_byte_func_t input_catchall_callback;
// only called if more specific callback is not matched
midi_var_byte_func_t input_fallthrough_callback;
// called if registered, independent of other callbacks
midi_var_byte_func_t input_catchall_callback;
//pre input processing function
midi_no_byte_func_t pre_input_process_callback;
// pre input processing function
midi_no_byte_func_t pre_input_process_callback;
//for internal input processing
uint8_t input_buffer[3];
input_state_t input_state;
uint16_t input_count;
// for internal input processing
uint8_t input_buffer[3];
input_state_t input_state;
uint16_t input_count;
//for queueing data between the input and the processing functions
uint8_t input_queue_data[MIDI_INPUT_QUEUE_LENGTH];
byteQueue_t input_queue;
// for queueing data between the input and the processing functions
uint8_t input_queue_data[MIDI_INPUT_QUEUE_LENGTH];
byteQueue_t input_queue;
};
/**
@ -122,7 +117,7 @@ struct _midi_device {
* @param cnt the number of bytes you are processing
* @param input the bytes to process
*/
void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input);
void midi_device_input(MidiDevice* device, uint8_t cnt, uint8_t* input);
/**
* @brief Set the callback function that will be used for sending output
@ -134,7 +129,7 @@ void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input);
* \param device the midi device to associate this callback with
* \param send_func the callback function that will do the sending
*/
void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_func);
void midi_device_set_send_func(MidiDevice* device, midi_var_byte_func_t send_func);
/**
* @brief Set a callback which is called at the beginning of the
@ -145,12 +140,12 @@ void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_fu
* \param device the midi device to associate this callback with
* \param midi_no_byte_func_t the actual callback function
*/
void midi_device_set_pre_input_process_func(MidiDevice * device, midi_no_byte_func_t pre_process_func);
void midi_device_set_pre_input_process_func(MidiDevice* device, midi_no_byte_func_t pre_process_func);
/**@}*/
#ifdef __cplusplus
}
#endif
#endif
#endif

44
tmk_core/protocol/midi/midi_function_types.h Executable file → Normal file
View file

@ -1,20 +1,20 @@
//midi for embedded chips,
//Copyright 2010 Alex Norman
// midi for embedded chips,
// Copyright 2010 Alex Norman
//
//This file is part of avr-midi.
// This file is part of avr-midi.
//
//avr-midi is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-midi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-midi is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-midi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
/**
* @file
@ -26,25 +26,25 @@
#ifdef __cplusplus
extern "C" {
#endif
#endif
#include <inttypes.h>
#include <stdbool.h>
//forward declaration
// forward declaration
typedef struct _midi_device MidiDevice;
typedef void (* midi_one_byte_func_t)(MidiDevice * device, uint8_t byte);
typedef void (* midi_two_byte_func_t)(MidiDevice * device, uint8_t byte0, uint8_t byte1);
typedef void (* midi_three_byte_func_t)(MidiDevice * device, uint8_t byte0, uint8_t byte1, uint8_t byte2);
//all bytes after count bytes should be ignored
typedef void (* midi_var_byte_func_t)(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2);
typedef void (*midi_one_byte_func_t)(MidiDevice *device, uint8_t byte);
typedef void (*midi_two_byte_func_t)(MidiDevice *device, uint8_t byte0, uint8_t byte1);
typedef void (*midi_three_byte_func_t)(MidiDevice *device, uint8_t byte0, uint8_t byte1, uint8_t byte2);
// all bytes after count bytes should be ignored
typedef void (*midi_var_byte_func_t)(MidiDevice *device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2);
//the start byte tells you how far into the sysex message you are, the data_length tells you how many bytes data is
typedef void (* midi_sysex_func_t)(MidiDevice * device, uint16_t start_byte, uint8_t data_length, uint8_t *data);
// the start byte tells you how far into the sysex message you are, the data_length tells you how many bytes data is
typedef void (*midi_sysex_func_t)(MidiDevice *device, uint16_t start_byte, uint8_t data_length, uint8_t *data);
#ifdef __cplusplus
}
#endif
#endif
#endif

View file

@ -5,7 +5,7 @@
#include "usb_descriptor.h"
#include "process_midi.h"
#if API_SYSEX_ENABLE
#include "api.h"
# include "api.h"
#endif
/*******************************************************************************
@ -23,162 +23,154 @@ MidiDevice midi_device;
#define SYS_COMMON_2 0x20
#define SYS_COMMON_3 0x30
static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
MIDI_EventPacket_t event;
event.Data1 = byte0;
event.Data2 = byte1;
event.Data3 = byte2;
static void usb_send_func(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
MIDI_EventPacket_t event;
event.Data1 = byte0;
event.Data2 = byte1;
event.Data3 = byte2;
uint8_t cable = 0;
uint8_t cable = 0;
//if the length is undefined we assume it is a SYSEX message
if (midi_packet_length(byte0) == UNDEFINED) {
switch(cnt) {
case 3:
if (byte2 == SYSEX_END)
event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_3);
else
event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
break;
case 2:
if (byte1 == SYSEX_END)
event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_2);
else
event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
break;
case 1:
if (byte0 == SYSEX_END)
event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_1);
else
event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
break;
default:
return; //invalid cnt
// if the length is undefined we assume it is a SYSEX message
if (midi_packet_length(byte0) == UNDEFINED) {
switch (cnt) {
case 3:
if (byte2 == SYSEX_END)
event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_3);
else
event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
break;
case 2:
if (byte1 == SYSEX_END)
event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_2);
else
event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
break;
case 1:
if (byte0 == SYSEX_END)
event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_1);
else
event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
break;
default:
return; // invalid cnt
}
} else {
// deal with 'system common' messages
// TODO are there any more?
switch (byte0 & 0xF0) {
case MIDI_SONGPOSITION:
event.Event = MIDI_EVENT(cable, SYS_COMMON_3);
break;
case MIDI_SONGSELECT:
case MIDI_TC_QUARTERFRAME:
event.Event = MIDI_EVENT(cable, SYS_COMMON_2);
break;
default:
event.Event = MIDI_EVENT(cable, byte0);
break;
}
}
} else {
//deal with 'system common' messages
//TODO are there any more?
switch(byte0 & 0xF0){
case MIDI_SONGPOSITION:
event.Event = MIDI_EVENT(cable, SYS_COMMON_3);
break;
case MIDI_SONGSELECT:
case MIDI_TC_QUARTERFRAME:
event.Event = MIDI_EVENT(cable, SYS_COMMON_2);
break;
default:
event.Event = MIDI_EVENT(cable, byte0);
break;
}
}
send_midi_packet(&event);
send_midi_packet(&event);
}
static void usb_get_midi(MidiDevice * device) {
MIDI_EventPacket_t event;
while (recv_midi_packet(&event)) {
static void usb_get_midi(MidiDevice* device) {
MIDI_EventPacket_t event;
while (recv_midi_packet(&event)) {
midi_packet_length_t length = midi_packet_length(event.Data1);
uint8_t input[3];
input[0] = event.Data1;
input[1] = event.Data2;
input[2] = event.Data3;
if (length == UNDEFINED) {
// sysex
if (event.Event == MIDI_EVENT(0, SYSEX_START_OR_CONT) || event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_3)) {
length = 3;
} else if (event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_2)) {
length = 2;
} else if (event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_1)) {
length = 1;
} else {
// XXX what to do?
}
}
midi_packet_length_t length = midi_packet_length(event.Data1);
uint8_t input[3];
input[0] = event.Data1;
input[1] = event.Data2;
input[2] = event.Data3;
if (length == UNDEFINED) {
//sysex
if (event.Event == MIDI_EVENT(0, SYSEX_START_OR_CONT) || event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_3)) {
length = 3;
} else if (event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_2)) {
length = 2;
} else if(event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_1)) {
length = 1;
} else {
//XXX what to do?
}
// pass the data to the device input function
if (length != UNDEFINED) midi_device_input(device, length, input);
}
//pass the data to the device input function
if (length != UNDEFINED)
midi_device_input(device, length, input);
}
}
static void fallthrough_callback(MidiDevice * device,
uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2){
static void fallthrough_callback(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
#ifdef AUDIO_ENABLE
if (cnt == 3) {
switch (byte0 & 0xF0) {
case MIDI_NOTEON:
play_note(((double)261.6)*pow(2.0, -4.0)*pow(2.0,(byte1 & 0x7F)/12.0), (byte2 & 0x7F) / 8);
break;
case MIDI_NOTEOFF:
stop_note(((double)261.6)*pow(2.0, -4.0)*pow(2.0,(byte1 & 0x7F)/12.0));
break;
if (cnt == 3) {
switch (byte0 & 0xF0) {
case MIDI_NOTEON:
play_note(((double)261.6) * pow(2.0, -4.0) * pow(2.0, (byte1 & 0x7F) / 12.0), (byte2 & 0x7F) / 8);
break;
case MIDI_NOTEOFF:
stop_note(((double)261.6) * pow(2.0, -4.0) * pow(2.0, (byte1 & 0x7F) / 12.0));
break;
}
}
if (byte0 == MIDI_STOP) {
stop_all_notes();
}
}
if (byte0 == MIDI_STOP) {
stop_all_notes();
}
#endif
}
static void cc_callback(MidiDevice * device,
uint8_t chan, uint8_t num, uint8_t val) {
//sending it back on the next channel
// midi_send_cc(device, (chan + 1) % 16, num, val);
static void cc_callback(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t val) {
// sending it back on the next channel
// midi_send_cc(device, (chan + 1) % 16, num, val);
}
#ifdef API_SYSEX_ENABLE
uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
static void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) {
// SEND_STRING("\n");
// send_word(start);
// SEND_STRING(": ");
// Don't store the header
int16_t pos = start - 4;
for (uint8_t place = 0; place < length; place++) {
// send_byte(*data);
if (pos >= 0) {
if (*data == 0xF7) {
// SEND_STRING("\nRD: ");
// for (uint8_t i = 0; i < start + place + 1; i++){
// send_byte(midi_buffer[i]);
// SEND_STRING(" ");
// }
const unsigned decoded_length = sysex_decoded_length(pos);
uint8_t decoded[API_SYSEX_MAX_SIZE];
sysex_decode(decoded, midi_buffer, pos);
process_api(decoded_length, decoded);
return;
}
else if (pos >= MIDI_SYSEX_BUFFER) {
return;
}
midi_buffer[pos] = *data;
}
// SEND_STRING(" ");
data++;
pos++;
}
static void sysex_callback(MidiDevice* device, uint16_t start, uint8_t length, uint8_t* data) {
// SEND_STRING("\n");
// send_word(start);
// SEND_STRING(": ");
// Don't store the header
int16_t pos = start - 4;
for (uint8_t place = 0; place < length; place++) {
// send_byte(*data);
if (pos >= 0) {
if (*data == 0xF7) {
// SEND_STRING("\nRD: ");
// for (uint8_t i = 0; i < start + place + 1; i++){
// send_byte(midi_buffer[i]);
// SEND_STRING(" ");
// }
const unsigned decoded_length = sysex_decoded_length(pos);
uint8_t decoded[API_SYSEX_MAX_SIZE];
sysex_decode(decoded, midi_buffer, pos);
process_api(decoded_length, decoded);
return;
} else if (pos >= MIDI_SYSEX_BUFFER) {
return;
}
midi_buffer[pos] = *data;
}
// SEND_STRING(" ");
data++;
pos++;
}
}
#endif
void midi_init(void);
void setup_midi(void)
{
void setup_midi(void) {
#ifdef MIDI_ADVANCED
midi_init();
midi_init();
#endif
midi_device_init(&midi_device);
midi_device_set_send_func(&midi_device, usb_send_func);
midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
midi_register_fallthrough_callback(&midi_device, fallthrough_callback);
midi_register_cc_callback(&midi_device, cc_callback);
midi_device_init(&midi_device);
midi_device_set_send_func(&midi_device, usb_send_func);
midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
midi_register_fallthrough_callback(&midi_device, fallthrough_callback);
midi_register_cc_callback(&midi_device, cc_callback);
#ifdef API_SYSEX_ENABLE
midi_register_sysex_callback(&midi_device, sysex_callback);
midi_register_sysex_callback(&midi_device, sysex_callback);
#endif
}

View file

@ -1,9 +1,9 @@
#pragma once
#ifdef MIDI_ENABLE
#include "midi.h"
extern MidiDevice midi_device;
void setup_midi(void);
void send_midi_packet(MIDI_EventPacket_t* event);
bool recv_midi_packet(MIDI_EventPacket_t* const event);
# include "midi.h"
extern MidiDevice midi_device;
void setup_midi(void);
void send_midi_packet(MIDI_EventPacket_t* event);
bool recv_midi_packet(MIDI_EventPacket_t* const event);
#endif

158
tmk_core/protocol/midi/sysex_tools.c Executable file → Normal file
View file

@ -1,99 +1,97 @@
//midi for embedded chips,
//Copyright 2010 Alex Norman
// midi for embedded chips,
// Copyright 2010 Alex Norman
//
//This file is part of avr-midi.
// This file is part of avr-midi.
//
//avr-midi is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-midi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-midi is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-midi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
#include "sysex_tools.h"
uint16_t sysex_encoded_length(uint16_t decoded_length){
uint8_t remainder = decoded_length % 7;
if (remainder)
return (decoded_length / 7) * 8 + remainder + 1;
else
return (decoded_length / 7) * 8;
uint16_t sysex_encoded_length(uint16_t decoded_length) {
uint8_t remainder = decoded_length % 7;
if (remainder)
return (decoded_length / 7) * 8 + remainder + 1;
else
return (decoded_length / 7) * 8;
}
uint16_t sysex_decoded_length(uint16_t encoded_length){
uint8_t remainder = encoded_length % 8;
if (remainder)
return (encoded_length / 8) * 7 + remainder - 1;
else
return (encoded_length / 8) * 7;
uint16_t sysex_decoded_length(uint16_t encoded_length) {
uint8_t remainder = encoded_length % 8;
if (remainder)
return (encoded_length / 8) * 7 + remainder - 1;
else
return (encoded_length / 8) * 7;
}
uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, const uint16_t length){
uint16_t encoded_full = length / 7; //number of full 8 byte sections from 7 bytes of input
uint16_t i,j;
uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, const uint16_t length) {
uint16_t encoded_full = length / 7; // number of full 8 byte sections from 7 bytes of input
uint16_t i, j;
//fill out the fully encoded sections
for(i = 0; i < encoded_full; i++) {
uint16_t encoded_msb_idx = i * 8;
uint16_t input_start_idx = i * 7;
encoded[encoded_msb_idx] = 0;
for(j = 0; j < 7; j++){
uint8_t current = source[input_start_idx + j];
encoded[encoded_msb_idx] |= (0x80 & current) >> (1 + j);
encoded[encoded_msb_idx + 1 + j] = 0x7F & current;
}
}
// fill out the fully encoded sections
for (i = 0; i < encoded_full; i++) {
uint16_t encoded_msb_idx = i * 8;
uint16_t input_start_idx = i * 7;
encoded[encoded_msb_idx] = 0;
for (j = 0; j < 7; j++) {
uint8_t current = source[input_start_idx + j];
encoded[encoded_msb_idx] |= (0x80 & current) >> (1 + j);
encoded[encoded_msb_idx + 1 + j] = 0x7F & current;
}
}
//fill out the rest if there is any more
uint8_t remainder = length % 7;
if (remainder) {
uint16_t encoded_msb_idx = encoded_full * 8;
uint16_t input_start_idx = encoded_full * 7;
encoded[encoded_msb_idx] = 0;
for(j = 0; j < remainder; j++){
uint8_t current = source[input_start_idx + j];
encoded[encoded_msb_idx] |= (0x80 & current) >> (1 + j);
encoded[encoded_msb_idx + 1 + j] = 0x7F & current;
}
return encoded_msb_idx + remainder + 1;
} else {
return encoded_full * 8;
}
// fill out the rest if there is any more
uint8_t remainder = length % 7;
if (remainder) {
uint16_t encoded_msb_idx = encoded_full * 8;
uint16_t input_start_idx = encoded_full * 7;
encoded[encoded_msb_idx] = 0;
for (j = 0; j < remainder; j++) {
uint8_t current = source[input_start_idx + j];
encoded[encoded_msb_idx] |= (0x80 & current) >> (1 + j);
encoded[encoded_msb_idx + 1 + j] = 0x7F & current;
}
return encoded_msb_idx + remainder + 1;
} else {
return encoded_full * 8;
}
}
uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, const uint16_t length){
uint16_t decoded_full = length / 8;
uint16_t i,j;
uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, const uint16_t length) {
uint16_t decoded_full = length / 8;
uint16_t i, j;
if (length < 2)
return 0;
if (length < 2) return 0;
//fill out the fully encoded sections
for(i = 0; i < decoded_full; i++) {
uint16_t encoded_msb_idx = i * 8;
uint16_t output_start_index = i * 7;
for(j = 0; j < 7; j++){
decoded[output_start_index + j] = 0x7F & source[encoded_msb_idx + j + 1];
decoded[output_start_index + j] |= (0x80 & (source[encoded_msb_idx] << (1 + j)));
}
}
uint8_t remainder = length % 8;
if (remainder) {
uint16_t encoded_msb_idx = decoded_full * 8;
uint16_t output_start_index = decoded_full * 7;
for(j = 0; j < (remainder - 1); j++) {
decoded[output_start_index + j] = 0x7F & source[encoded_msb_idx + j + 1];
decoded[output_start_index + j] |= (0x80 & (source[encoded_msb_idx] << (1 + j)));
}
return decoded_full * 7 + remainder - 1;
} else {
return decoded_full * 7;
}
// fill out the fully encoded sections
for (i = 0; i < decoded_full; i++) {
uint16_t encoded_msb_idx = i * 8;
uint16_t output_start_index = i * 7;
for (j = 0; j < 7; j++) {
decoded[output_start_index + j] = 0x7F & source[encoded_msb_idx + j + 1];
decoded[output_start_index + j] |= (0x80 & (source[encoded_msb_idx] << (1 + j)));
}
}
uint8_t remainder = length % 8;
if (remainder) {
uint16_t encoded_msb_idx = decoded_full * 8;
uint16_t output_start_index = decoded_full * 7;
for (j = 0; j < (remainder - 1); j++) {
decoded[output_start_index + j] = 0x7F & source[encoded_msb_idx + j + 1];
decoded[output_start_index + j] |= (0x80 & (source[encoded_msb_idx] << (1 + j)));
}
return decoded_full * 7 + remainder - 1;
} else {
return decoded_full * 7;
}
}

34
tmk_core/protocol/midi/sysex_tools.h Executable file → Normal file
View file

@ -1,27 +1,27 @@
//midi for embedded chips,
//Copyright 2010 Alex Norman
// midi for embedded chips,
// Copyright 2010 Alex Norman
//
//This file is part of avr-midi.
// This file is part of avr-midi.
//
//avr-midi is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
// avr-midi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//avr-midi is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// avr-midi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
#ifndef SYSEX_TOOLS_H
#define SYSEX_TOOLS_H
#ifdef __cplusplus
extern "C" {
#endif
#endif
#include <inttypes.h>
@ -31,7 +31,7 @@ extern "C" {
*
* These functions are for converting data to and from a "midi-safe" format,
* which can be use to send data with sysex messages. Sysex messages may only
* contain data where the to bit is not set.
* contain data where the to bit is not set.
*
* An "encoded" midi message is one that contains all of the data from its
* original state, but does not have any of the top bits set.
@ -70,7 +70,7 @@ uint16_t sysex_decoded_length(uint16_t encoded_length);
* @param encoded The output data buffer, must be at least sysex_encoded_length(length) bytes long.
* @param source The input buffer of data to be encoded.
* @param length The number of bytes from the input buffer to encode.
*
*
* @return number of bytes encoded.
*/
uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, uint16_t length);
@ -81,7 +81,7 @@ uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, uint16_t length);
* @param decoded The output data buffer, must be at least sysex_decoded_length(length) bytes long.
* @param source The input buffer of data to be decoded.
* @param length The number of bytes from the input buffer to decode.
*
*
* @return number of bytes decoded.
*/
uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, uint16_t length);
@ -90,6 +90,6 @@ uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, uint16_t length);
#ifdef __cplusplus
}
#endif
#endif
#endif

View file

@ -40,41 +40,34 @@ POSSIBILITY OF SUCH DAMAGE.
#include <avr/interrupt.h>
#include "news.h"
void news_init(void)
{
NEWS_KBD_RX_INIT();
}
void news_init(void) { NEWS_KBD_RX_INIT(); }
// RX ring buffer
#define RBUF_SIZE 8
#define RBUF_SIZE 8
static uint8_t rbuf[RBUF_SIZE];
static uint8_t rbuf_head = 0;
static uint8_t rbuf_tail = 0;
uint8_t news_recv(void)
{
uint8_t news_recv(void) {
uint8_t data = 0;
if (rbuf_head == rbuf_tail) {
return 0;
}
data = rbuf[rbuf_tail];
data = rbuf[rbuf_tail];
rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
return data;
}
// USART RX complete interrupt
ISR(NEWS_KBD_RX_VECT)
{
ISR(NEWS_KBD_RX_VECT) {
uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
if (next != rbuf_tail) {
rbuf[rbuf_head] = NEWS_KBD_RX_DATA;
rbuf_head = next;
rbuf_head = next;
}
}
/*
SONY NEWS Keyboard Protocol
===========================

Some files were not shown because too many files have changed in this diff Show more