forked from lucysrausch/hoverboard-firmware-hack
ADD: Wii Nunchuck control
This commit is contained in:
@@ -8,6 +8,13 @@ TIM_HandleTypeDef TimHandle;
|
||||
uint16_t ppm_captured_value[PPM_NUM_CHANNELS+1] = {0};
|
||||
uint8_t ppm_count = 0;
|
||||
uint32_t timeout = 100;
|
||||
uint8_t nunchuck_data[6] = {0};
|
||||
|
||||
uint8_t ai2cBuffer[6];
|
||||
|
||||
extern I2C_HandleTypeDef hi2c2;
|
||||
DMA_HandleTypeDef hdma_i2c2_rx;
|
||||
DMA_HandleTypeDef hdma_i2c2_tx;
|
||||
|
||||
void PPM_ISR_Callback() {
|
||||
// Dummy loop with 16 bit count wrap around
|
||||
@@ -47,3 +54,33 @@ void PPM_Init() {
|
||||
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
|
||||
HAL_TIM_Base_Start(&TimHandle);
|
||||
}
|
||||
|
||||
|
||||
void Nunchuck_Init() {
|
||||
//-- START -- init WiiNunchuck
|
||||
ai2cBuffer[0] = 0xF0;
|
||||
ai2cBuffer[1] = 0x55;
|
||||
//Originale
|
||||
ai2cBuffer[0] = 0x40;
|
||||
ai2cBuffer[1] = 0x00;
|
||||
//HAL_I2C_Master_Transmit_DMA(&hi2c2, 0xA4, (uint8_t*)ai2cBuffer, 2);
|
||||
//while(wii_JOYdati.I2CTxDone ==0);
|
||||
//wii_JOYdati.I2CTxDone = 0;
|
||||
HAL_I2C_Master_Transmit(&hi2c2,0xA4,(uint8_t*)ai2cBuffer, 2, 100);
|
||||
HAL_Delay(10);
|
||||
//wii_JOYdati.done = 0;
|
||||
}
|
||||
|
||||
void Nunchuck_Read() {
|
||||
ai2cBuffer[0] = 0x00;
|
||||
HAL_I2C_Master_Transmit(&hi2c2,0xA4,(uint8_t*)ai2cBuffer, 1, 100);
|
||||
HAL_Delay(2);
|
||||
HAL_I2C_Master_Receive(&hi2c2,0xA4,(uint8_t*)ai2cBuffer, 6, 100);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
nunchuck_data[i] = (ai2cBuffer[i] ^ 0x17) + 0x17;
|
||||
}
|
||||
//setScopeChannel(0, (int)nunchuck_data[0]);
|
||||
//setScopeChannel(1, (int)nunchuck_data[1]);
|
||||
//setScopeChannel(2, (int)nunchuck_data[5] & 1);
|
||||
//setScopeChannel(3, ((int)nunchuck_data[5] >> 1) & 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user