573 lines
18 KiB
C
573 lines
18 KiB
C
|
|
#include "includes.h"
|
|||
|
|
|
|||
|
|
|
|||
|
|
// Э<><D0AD>֡ͷ/֡β
|
|||
|
|
#define FRAME_SYS_HEAD 0xF0
|
|||
|
|
#define FRAME_SYS_TAIL 0xF7
|
|||
|
|
#define FRAME_MIDI_NOTEON 0x90
|
|||
|
|
#define FRAME_MIDI_NOTEOFF 0x80
|
|||
|
|
#define FRAME_MIDI_PROCHANGE 0xC0
|
|||
|
|
#define UART4_RCV_TIMEOUT_MS 50
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief UART4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ö<EFBFBD><EFBFBD>
|
|||
|
|
*/
|
|||
|
|
typedef enum
|
|||
|
|
{
|
|||
|
|
UART4_RCV_BUFF_IDLE, // <20><><EFBFBD><EFBFBD>״̬
|
|||
|
|
UART4_RCV_BUFF_HEAD, // <20><><EFBFBD><EFBFBD>֡ͷ<D6A1><CDB7>̶<EFBFBD><CCB6>ֽ<EFBFBD>(0x60/0x51)
|
|||
|
|
UART4_RCV_BUFF_CMD1, // <20><>ָ<EFBFBD><D6B8>
|
|||
|
|
UART4_RCV_BUFF_CMD2, // <20><>ָ<EFBFBD><D6B8>
|
|||
|
|
UART4_RCV_BUFF_DATA, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
UART4_RCV_BUFF_END, // ֡β<D6A1><CEB2><EFBFBD><EFBFBD>
|
|||
|
|
UART4_RCV_BUFF_MIDI1,
|
|||
|
|
UART4_RCV_BUFF_MIDI2,
|
|||
|
|
UART4_RCV_BUFF_MIDIEND
|
|||
|
|
} UART4_RCV_StatusType;
|
|||
|
|
|
|||
|
|
#define UART4_PROCESS_BUFF_SIZE 32
|
|||
|
|
|
|||
|
|
// UART4<54><34><EFBFBD><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>
|
|||
|
|
static UART4_RCV_StatusType UART4_RCV_Status = UART4_RCV_BUFF_IDLE;
|
|||
|
|
static uint8_t UART4_Process_Buff[UART4_PROCESS_BUFF_SIZE];
|
|||
|
|
static uint8_t UART4_RCV_cnt = 0;
|
|||
|
|
//static uint32_t UART4_RCV_Last_Tick = 0;
|
|||
|
|
//static uint8_t expect_data_len = 0;
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD>壨<EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>UART3<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*/
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
uint8_t cmd[2]; // <20><>ָ<EFBFBD><D6B8>+<2B><>ָ<EFBFBD><D6B8>
|
|||
|
|
void (*handler)(uint8_t *data);// <20><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
} BLE_SysExCmdItem;
|
|||
|
|
|
|||
|
|
|
|||
|
|
// ==============================
|
|||
|
|
// ָ<><EFBFBD><EEB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB> static<69><63>
|
|||
|
|
// ==============================
|
|||
|
|
//static void handleDevDisconnect(uint8_t *data);
|
|||
|
|
//static void handleDevConnect(uint8_t *data);
|
|||
|
|
//static void handleDevName(uint8_t *data);
|
|||
|
|
//static void handleFwMainVer(uint8_t *data);
|
|||
|
|
//static void handleSoundVer(uint8_t *data);
|
|||
|
|
//static void handleUIVer(uint8_t *data);
|
|||
|
|
//static void handleOtherInfo(uint8_t *data);
|
|||
|
|
//static void handleDevCode(uint8_t *data);
|
|||
|
|
//static void handleAutoPowerOff(uint8_t *data);
|
|||
|
|
|
|||
|
|
static void handleReadRhythmMap(uint8_t *data);
|
|||
|
|
static void handlePitchOffset(uint8_t *data);
|
|||
|
|
static void handleChordOffset(uint8_t *data);
|
|||
|
|
//static void handleResetChordMap(uint8_t *data);
|
|||
|
|
|
|||
|
|
//static void handleRhythmStyle(uint8_t *data);
|
|||
|
|
static void handleStringTimbre(uint8_t *data);
|
|||
|
|
static void handleBPM(uint8_t *data);
|
|||
|
|
static void handleTranspose(uint8_t *data);
|
|||
|
|
|
|||
|
|
static void handleLED0(uint8_t *data);
|
|||
|
|
static void handleLED1(uint8_t *data);
|
|||
|
|
static void handleLED2(uint8_t *data);
|
|||
|
|
static void handleLED3(uint8_t *data);
|
|||
|
|
static void handleLED4(uint8_t *data);
|
|||
|
|
static void handleLED5(uint8_t *data);
|
|||
|
|
static void handleLED6(uint8_t *data);
|
|||
|
|
//static void handleStopPlay(uint8_t *data);
|
|||
|
|
|
|||
|
|
//static void handleDeviceReset(uint8_t *data);
|
|||
|
|
|
|||
|
|
static void handleIntro(uint8_t *data);
|
|||
|
|
static void handleInterlude(uint8_t *data);
|
|||
|
|
static void handleOutro(uint8_t *data);
|
|||
|
|
static void handleEnd(uint8_t *data);
|
|||
|
|
static void handleSectionA(uint8_t *data);
|
|||
|
|
static void handleSectionB(uint8_t *data);
|
|||
|
|
static void handleSectionC(uint8_t *data);
|
|||
|
|
static void handleSectionD(uint8_t *data);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/*************************************************
|
|||
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*************************************************/
|
|||
|
|
static const BLE_SysExCmdItem bleSysExCmdTable[] =
|
|||
|
|
{
|
|||
|
|
// //======== 1. <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ 0x01 ========
|
|||
|
|
// {{0x01, 0x00}, handleDevDisconnect}, // <20>Ͽ<EFBFBD><CFBF>豸
|
|||
|
|
// {{0x01, 0x01}, handleDevConnect}, // <20><><EFBFBD><EFBFBD><EFBFBD>豸
|
|||
|
|
// {{0x01, 0x02}, handleDevName}, // <20><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>
|
|||
|
|
// {{0x01, 0x03}, handleFwMainVer}, // <20>̼<EFBFBD><CCBC><EFBFBD><EFBFBD>汾
|
|||
|
|
// {{0x01, 0x04}, handleSoundVer}, // <20><>Դ<EFBFBD>汾
|
|||
|
|
// {{0x01, 0x05}, handleUIVer}, // UI<55>汾
|
|||
|
|
// {{0x01, 0x06}, handleOtherInfo}, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
// {{0x01, 0x07}, handleDevCode}, // <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
|||
|
|
// {{0x01, 0x0A}, handleAutoPowerOff}, // <20>Զ<EFBFBD><D4B6>ػ<EFBFBD>
|
|||
|
|
//
|
|||
|
|
// //======== 2. ӳ<><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0x02 ========
|
|||
|
|
{{0x02, 0x01}, handleReadRhythmMap}, // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>
|
|||
|
|
{{0x02, 0x02}, handlePitchOffset}, // Pitchƫ<68><C6AB>
|
|||
|
|
{{0x02, 0x03}, handleChordOffset}, // Chordƫ<64><C6AB>
|
|||
|
|
// {{0x02, 0x04}, handleResetChordMap}, // <20><><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>ӳ<EFBFBD><D3B3>Ĭ<EFBFBD><C4AC>ֵ
|
|||
|
|
|
|||
|
|
//======== 3. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д 0x03 ========
|
|||
|
|
// {{0x03, 0x04}, handleRhythmStyle}, // <20><>ȡ/<2F><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{{0x03, 0x05}, handleStringTimbre}, // <20><>ȡ/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
|
{{0x03, 0x06}, handleBPM}, // <20><>ȡ/<2F><><EFBFBD><EFBFBD>BPM
|
|||
|
|
{{0x03, 0x07}, handleTranspose}, // <20><>ȡ/<2F><><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>
|
|||
|
|
|
|||
|
|
//======== 4. <20><><EFBFBD><EFBFBD>/LED<45><44><EFBFBD><EFBFBD> 0x04 ========
|
|||
|
|
{{0x04, 0x00}, handleLED0}, // <20><>1<EFBFBD><31>LED
|
|||
|
|
{{0x04, 0x01}, handleLED1}, // <20><>2<EFBFBD><32>LED
|
|||
|
|
{{0x04, 0x02}, handleLED2}, // <20><>3<EFBFBD><33>LED
|
|||
|
|
{{0x04, 0x03}, handleLED3}, // <20><>4<EFBFBD><34>LED
|
|||
|
|
{{0x04, 0x04}, handleLED4}, // <20><>5<EFBFBD><35>LED
|
|||
|
|
{{0x04, 0x05}, handleLED5}, // <20><>6<EFBFBD><36>LED
|
|||
|
|
{{0x04, 0x06}, handleLED6}, // <20><>7<EFBFBD><37>LED
|
|||
|
|
// {{0x04, 0x07}, handleStopPlay}, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
// //======== 5. <20><>λ/<2F>ػ<EFBFBD> 0x05 ========
|
|||
|
|
// {{0x05, 0x00}, handleDeviceReset}, // <20>豸<EFBFBD><E8B1B8>λ
|
|||
|
|
//
|
|||
|
|
// //======== 6. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת 0x06 ========
|
|||
|
|
{{0x06, 0x01}, handleIntro}, // ǰ<><C7B0>
|
|||
|
|
{{0x06, 0x02}, handleInterlude}, // <20><><EFBFBD><EFBFBD>
|
|||
|
|
{{0x06, 0x03}, handleOutro}, // β<><CEB2>
|
|||
|
|
{{0x04, 0x07}, handleEnd}, // end
|
|||
|
|
{{0x06, 0x05}, handleSectionA}, // A<><41>
|
|||
|
|
{{0x06, 0x06}, handleSectionB}, // B<><42>
|
|||
|
|
{{0x06, 0x07}, handleSectionC}, // C<><43>
|
|||
|
|
{{0x06, 0x08}, handleSectionD}, // D<><44>
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
#define BLE_SYS_EX_CMD_COUNT (sizeof(bleSysExCmdTable) / sizeof(BLE_SysExCmdItem))
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysExָ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
* @param data: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
* @param cnt: ֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*/
|
|||
|
|
void processBLESysEXData(uint8_t* data, uint8_t cnt)
|
|||
|
|
{
|
|||
|
|
//ResetAutoPowerCount();
|
|||
|
|
// <20><><EFBFBD><EFBFBD>֡У<D6A1><D0A3>
|
|||
|
|
if (data[0] != FRAME_SYS_HEAD || data[cnt - 1] != FRAME_SYS_TAIL || cnt > UART4_PROCESS_BUFF_SIZE || data[1] != 0x60)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ȡ <20><>ָ<EFBFBD><D6B8> + <20><>ָ<EFBFBD><D6B8>
|
|||
|
|
uint8_t cmd[2] = {data[2], data[3]};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ƥ<EFBFBD><C6A5>
|
|||
|
|
for (uint8_t i = 0; i < BLE_SYS_EX_CMD_COUNT; i++)
|
|||
|
|
{
|
|||
|
|
if (memcmp(cmd, bleSysExCmdTable[i].cmd, 2) == 0)
|
|||
|
|
{
|
|||
|
|
if (bleSysExCmdTable[i].handler != NULL)
|
|||
|
|
{
|
|||
|
|
bleSysExCmdTable[i].handler(data);
|
|||
|
|
}
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
void UART4_Data_Process(volatile uint8_t* data)
|
|||
|
|
{
|
|||
|
|
uint8_t rcv = *data;
|
|||
|
|
uint32_t now = rt_tick_get();
|
|||
|
|
static uint32_t last_tick;
|
|||
|
|
if(now - last_tick >= UART4_RCV_TIMEOUT_MS)
|
|||
|
|
{
|
|||
|
|
last_tick = now;
|
|||
|
|
memset(UART4_Process_Buff, 0, sizeof(UART4_Process_Buff));
|
|||
|
|
UART4_RCV_cnt = 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
switch (UART4_RCV_Status)
|
|||
|
|
{
|
|||
|
|
case UART4_RCV_BUFF_IDLE:
|
|||
|
|
memset(UART4_Process_Buff, 0, sizeof(UART4_Process_Buff));
|
|||
|
|
UART4_RCV_cnt = 0;
|
|||
|
|
|
|||
|
|
switch(rcv & 0xF0)
|
|||
|
|
{
|
|||
|
|
case FRAME_SYS_HEAD:
|
|||
|
|
UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_HEAD;
|
|||
|
|
break;
|
|||
|
|
case FRAME_MIDI_NOTEON:
|
|||
|
|
case FRAME_MIDI_NOTEOFF:
|
|||
|
|
case FRAME_MIDI_PROCHANGE:
|
|||
|
|
UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_MIDI1;
|
|||
|
|
break;
|
|||
|
|
default:UART4_RCV_Status = UART4_RCV_BUFF_IDLE; return; break;
|
|||
|
|
}
|
|||
|
|
//UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
case UART4_RCV_BUFF_MIDI1:
|
|||
|
|
if((UART4_Process_Buff[0] & 0xF0) == FRAME_MIDI_PROCHANGE)
|
|||
|
|
{
|
|||
|
|
USART2_SendData(UART4_Process_Buff,UART4_RCV_cnt);
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_IDLE;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_MIDI2;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
case UART4_RCV_BUFF_MIDI2:
|
|||
|
|
UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
USART2_SendData(UART4_Process_Buff,UART4_RCV_cnt);
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_IDLE;
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
case UART4_RCV_BUFF_HEAD:
|
|||
|
|
if (UART4_RCV_cnt < UART4_PROCESS_BUFF_SIZE)
|
|||
|
|
{
|
|||
|
|
UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (rcv == 0x60)
|
|||
|
|
{
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_CMD1;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
// <20>Ƿ<EFBFBD><C7B7>ֽڣ<D6BD><DAA3><EFBFBD>λ
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_IDLE;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
case UART4_RCV_BUFF_CMD1:
|
|||
|
|
// <20><>ָ<EFBFBD><D6B8>
|
|||
|
|
if (UART4_RCV_cnt < UART4_PROCESS_BUFF_SIZE)
|
|||
|
|
{
|
|||
|
|
UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
}
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_CMD2;
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
case UART4_RCV_BUFF_CMD2:
|
|||
|
|
// <20><>ָ<EFBFBD><D6B8>
|
|||
|
|
if (UART4_RCV_cnt < UART4_PROCESS_BUFF_SIZE)
|
|||
|
|
{
|
|||
|
|
UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
}
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_DATA;
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
case UART4_RCV_BUFF_DATA:
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD>ݣ<EFBFBD>ֱ<EFBFBD><D6B1>֡β 0xF7
|
|||
|
|
if (UART4_RCV_cnt < UART4_PROCESS_BUFF_SIZE)
|
|||
|
|
{
|
|||
|
|
UART4_Process_Buff[UART4_RCV_cnt++] = rcv;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (rcv == FRAME_SYS_TAIL)
|
|||
|
|
{
|
|||
|
|
// ִ<><D6B4>ָ<EFBFBD><EFBFBD><EEB4A6>
|
|||
|
|
processBLESysEXData(UART4_Process_Buff, UART4_RCV_cnt);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD>λ״̬<D7B4><CCAC>
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_IDLE;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
default:
|
|||
|
|
// δ֪״̬ǿ<CCAC>Ƹ<EFBFBD>λ
|
|||
|
|
UART4_RCV_Status = UART4_RCV_BUFF_IDLE;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void handleStringTimbre(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
switch(data[4])
|
|||
|
|
{
|
|||
|
|
case 0:
|
|||
|
|
{
|
|||
|
|
uint8_t ReturnTimbre[8] = {0xF0,0x60,0x03,0x05,0x00,0x00,0x00,0xF7};
|
|||
|
|
ReturnTimbre[6] = mGuiData[GUI_TIMBRE_SELECT].Current;
|
|||
|
|
USART4_SendData(ReturnTimbre,sizeof(ReturnTimbre));
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case 1:
|
|||
|
|
{
|
|||
|
|
NvmParam_Type * nvm = drv_nvm_param_ptr();
|
|||
|
|
uint8_t new_val = data[6]; // <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ɫֵ
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ֵû<D6B5>䣬ֱ<E4A3AC><D6B1><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2>
|
|||
|
|
if (new_val == mGuiData[GUI_TIMBRE_SELECT].Current)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
mGuiData[GUI_TIMBRE_SELECT].Current = new_val;
|
|||
|
|
if(mGuiData[GUI_TAB_INDEX].Current != 3)
|
|||
|
|
{
|
|||
|
|
//Refresh_StringTimbre(last_value, &UI_Label[GUI_TIMBRE_SELECT], &mGuiData[GUI_TIMBRE_SELECT]);
|
|||
|
|
}
|
|||
|
|
if(nvm->param.Timbre != mGuiData[GUI_TIMBRE_SELECT].Current)
|
|||
|
|
{
|
|||
|
|
nvm->param.Timbre = mGuiData[GUI_TIMBRE_SELECT].Current;
|
|||
|
|
drv_nvm_save_to_flash();
|
|||
|
|
}
|
|||
|
|
// uint8_t buff[10] = {0,};
|
|||
|
|
// LCD_ShowString(200,30, Num_To_String(mGuiData[GUI_TIMBRE_SELECT].Current,buff,4), RED, WHITE, 16, 0);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//extern int8_t delta;
|
|||
|
|
extern STRING_MIDI USE_MIDI;
|
|||
|
|
static void handleTranspose(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
//uint8_t last_value;
|
|||
|
|
switch(data[4])
|
|||
|
|
{
|
|||
|
|
case 0:
|
|||
|
|
{
|
|||
|
|
uint8_t ReturnTranspose[8] = {0xF0,0x60,0x03,0x07,0x00,0x00,0x00,0xF7};
|
|||
|
|
ReturnTranspose[5] = mGuiData[GUI_TRANSPOSE].Current;
|
|||
|
|
USART4_SendData(ReturnTranspose,sizeof(ReturnTranspose));
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case 1:
|
|||
|
|
{
|
|||
|
|
NvmParam_Type * nvm = drv_nvm_param_ptr();
|
|||
|
|
uint8_t new_val = data[5]; // <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ɫֵ
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ֵû<D6B5>䣬ֱ<E4A3AC><D6B1><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2>
|
|||
|
|
if (new_val == mGuiData[GUI_TRANSPOSE].Current)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
mGuiData[GUI_TRANSPOSE].Current = new_val;
|
|||
|
|
if(mGuiData[GUI_TAB_INDEX].Current != 3)
|
|||
|
|
{
|
|||
|
|
Refresh_Transpose(&UI_Label[GUI_TRANSPOSE], &mGuiData[GUI_TRANSPOSE]);
|
|||
|
|
}
|
|||
|
|
if(nvm->param.Transpose != mGuiData[GUI_TRANSPOSE].Current)
|
|||
|
|
{
|
|||
|
|
nvm->param.Transpose = mGuiData[GUI_TRANSPOSE].Current;
|
|||
|
|
drv_nvm_save_to_flash();
|
|||
|
|
}
|
|||
|
|
// delta = new_trans - last_value;
|
|||
|
|
|
|||
|
|
// USE_MIDI.Midi_1 += delta;
|
|||
|
|
// USE_MIDI.Midi_2 += delta;
|
|||
|
|
// USE_MIDI.Midi_3 += delta;
|
|||
|
|
// USE_MIDI.Midi_4 += delta;
|
|||
|
|
// USE_MIDI.Midi_5 += delta;
|
|||
|
|
// USE_MIDI.Midi_6 += delta;
|
|||
|
|
|
|||
|
|
//AutoBandTop1_Note_On(USE_MIDI.Midi_6,0x50);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// <20>յ<EFBFBD>˫<EFBFBD>ֽ<EFBFBD> hi, lo<6C><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>BPM
|
|||
|
|
uint16_t Calc_BPM(uint8_t bpmHi, uint8_t bpmLo)
|
|||
|
|
{
|
|||
|
|
return (uint16_t)bpmHi * 128 + bpmLo;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>BPM<50><4D><EFBFBD><EFBFBD>ֳ<EFBFBD>hi<68><69>lo˫<6F>ֽ<EFBFBD>
|
|||
|
|
void Split_BPM(uint16_t target_bpm, uint8_t *hi_out, uint8_t *lo_out)
|
|||
|
|
{
|
|||
|
|
*hi_out = target_bpm / 128;
|
|||
|
|
*lo_out = target_bpm % 128;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void handleBPM(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
switch(data[4])
|
|||
|
|
{
|
|||
|
|
case 0:
|
|||
|
|
{
|
|||
|
|
uint8_t ReturnSpeed[8] = {0xF0,0x60,0x03,0x06,0x00,0x00,0x00,0xF7};
|
|||
|
|
ReturnSpeed[5] = mGuiData[GUI_SPEED].Current / 128;
|
|||
|
|
ReturnSpeed[6] = mGuiData[GUI_SPEED].Current % 128;
|
|||
|
|
USART4_SendData(ReturnSpeed,sizeof(ReturnSpeed));
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case 1:
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
NvmParam_Type * nvm = drv_nvm_param_ptr();
|
|||
|
|
uint16_t new_val = Calc_BPM(data[5],data[6]);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ֵû<D6B5>䣬ֱ<E4A3AC><D6B1><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2>
|
|||
|
|
if (new_val == mGuiData[GUI_SPEED].Current)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
mGuiData[GUI_SPEED].Current = new_val;
|
|||
|
|
if(mGuiData[GUI_TAB_INDEX].Current != 3)
|
|||
|
|
{
|
|||
|
|
Refresh_Transpose(&UI_Label[GUI_SPEED], &mGuiData[GUI_SPEED]);
|
|||
|
|
}
|
|||
|
|
if(nvm->param.BPM != mGuiData[GUI_SPEED].Current)
|
|||
|
|
{
|
|||
|
|
nvm->param.BPM = mGuiData[GUI_SPEED].Current;
|
|||
|
|
drv_nvm_save_to_flash();
|
|||
|
|
}
|
|||
|
|
AutoBandTop1_ChangeBPM(mGuiData[GUI_SPEED].Current);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void handleLED0(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
// DefaultTask_SendMsg(MSG_ID_LIGHT_LED, LED_L1, data[5], 0);
|
|||
|
|
BL_Sendmsg(MSG_ID_LIGHT_LED, LED_L1, data[5], 0);
|
|||
|
|
}
|
|||
|
|
static void handleLED1(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_LIGHT_LED, LED_L2, data[5], 0);
|
|||
|
|
}
|
|||
|
|
static void handleLED2(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_LIGHT_LED, LED_L3, data[5], 0);
|
|||
|
|
}
|
|||
|
|
static void handleLED3(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_LIGHT_LED, LED_L4, data[5], 0);
|
|||
|
|
}
|
|||
|
|
static void handleLED4(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_LIGHT_LED, LED_L5, data[5], 0);
|
|||
|
|
}
|
|||
|
|
static void handleLED5(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_LIGHT_LED, LED_L6, data[5], 0);
|
|||
|
|
}
|
|||
|
|
static void handleLED6(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_LIGHT_LED, LED_L7, data[5], 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void handlePitchOffset(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_PITCH_OFFSET, data[4]+1, data[5], 0);
|
|||
|
|
}
|
|||
|
|
static void handleChordOffset(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_CHORD_OFFSET, data[4]+1, data[5], 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
extern CHORD_TYPE_INDEX chord_type_index_map[22];
|
|||
|
|
static void handleReadRhythmMap(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
uint8_t ReadChordMap[47] = {0xF0, 0x60, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7};
|
|||
|
|
uint8_t chord_map = 0;
|
|||
|
|
for(uint8_t i = 1;i < 22;i ++)
|
|||
|
|
{
|
|||
|
|
ReadChordMap[3+i] = chord_type_index_map[i].PitchOffset;
|
|||
|
|
}
|
|||
|
|
for(uint8_t i = 25;i < 46;i ++)
|
|||
|
|
{
|
|||
|
|
switch(chord_type_index_map[i-24].type)
|
|||
|
|
{
|
|||
|
|
case 0:
|
|||
|
|
chord_map = 0;
|
|||
|
|
break;
|
|||
|
|
case 1:
|
|||
|
|
chord_map = 8;
|
|||
|
|
break;
|
|||
|
|
case 2:
|
|||
|
|
chord_map = 2;
|
|||
|
|
break;
|
|||
|
|
case 3:
|
|||
|
|
chord_map = 13;
|
|||
|
|
break;
|
|||
|
|
case 4:
|
|||
|
|
chord_map = 10;
|
|||
|
|
break;
|
|||
|
|
case 5:
|
|||
|
|
chord_map = 31;
|
|||
|
|
break;
|
|||
|
|
case 6:
|
|||
|
|
chord_map = 30;
|
|||
|
|
break;
|
|||
|
|
case 7:
|
|||
|
|
chord_map = 4;
|
|||
|
|
break;
|
|||
|
|
case 8:
|
|||
|
|
chord_map = 11;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
ReadChordMap[i] = chord_map;
|
|||
|
|
}
|
|||
|
|
USART4_SendData(ReadChordMap,sizeof(ReadChordMap));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void handleIntro(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_ADCIN1KEY, 3, 0, 0);
|
|||
|
|
}
|
|||
|
|
static void handleInterlude(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_ADCIN1KEY, 0, 0, 0);
|
|||
|
|
}
|
|||
|
|
static void handleOutro(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_ADCIN1KEY, 1, 0, 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void handleEnd(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
//DefaultTask_SendMsg(MSG_ID_ADCIN1KEY, 2, 0, 0);
|
|||
|
|
// osMutexAcquire(Tm1629Mutex,osWaitForever);
|
|||
|
|
// TM1629D_AllLedOff();
|
|||
|
|
// TM1629D_AllLedOn(LED_COLOR_G);
|
|||
|
|
// TM1629D_UpdateDisplay(0);
|
|||
|
|
// osMutexRelease(Tm1629Mutex);
|
|||
|
|
BL_Sendmsg(MSG_ID_ADCIN1KEY, 1, 0, 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void handleSectionA(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_KEY_1617, 3, 0, 0);
|
|||
|
|
}
|
|||
|
|
static void handleSectionB(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_KEY_1617, 2, 0, 0);
|
|||
|
|
}
|
|||
|
|
static void handleSectionC(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_KEY_1617, 1, 0, 0);
|
|||
|
|
}
|
|||
|
|
static void handleSectionD(uint8_t *data)
|
|||
|
|
{
|
|||
|
|
BL_Sendmsg(MSG_ID_KEY_1617, 0, 0, 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void BL_Sendmsg(uint16_t Data1, uint16_t Data2, uint16_t Data3, uint16_t Data4)
|
|||
|
|
{
|
|||
|
|
BLTask_Sendmsg(Data1, Data2, Data3, Data4);
|
|||
|
|
}
|