mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
fixed ADB interrupt timing, mouse working
This commit is contained in:
@@ -41,6 +41,8 @@
|
||||
// #define DEBUG1_HI() {}
|
||||
// #define DEBUG1_LOW() {}
|
||||
|
||||
#define ADB_CLK_35 34
|
||||
#define ADB_CLK_65 64
|
||||
|
||||
void adb_init(GPIO_TypeDef* data_port, uint16_t data_pin, GPIO_TypeDef* psw_port, uint16_t psw_pin);
|
||||
uint8_t adb_recv_cmd(uint8_t* data, uint8_t srq);
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -27,9 +27,9 @@ Project File Date: 01/01/2022
|
||||
<h2>Output:</h2>
|
||||
*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
|
||||
Build target 'my_adb'
|
||||
compiling adb.c...
|
||||
compiling main.c...
|
||||
linking...
|
||||
Program Size: Code=9092 RO-data=312 RW-data=60 ZI-data=1948
|
||||
Program Size: Code=9356 RO-data=312 RW-data=56 ZI-data=1952
|
||||
FromELF: creating hex file...
|
||||
"my_adb\my_adb.axf" - 0 Error(s), 0 Warning(s).
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
Dependencies for Project 'my_adb', Target 'my_adb': (DO NOT MODIFY !)
|
||||
CompilerVersion: 5060750::V5.06 update 6 (build 750)::ARMCC
|
||||
F (startup_stm32f042x6.s)(0x61D0CD73)(--cpu Cortex-M0 -g --apcs=interwork --pd "__MICROLIB SETA 1"
|
||||
|
||||
|
||||
-I.\RTE\_my_adb
|
||||
|
||||
-IC:\Users\allen\AppData\Local\Arm\Packs\ARM\CMSIS\5.6.0\CMSIS\Core\Include
|
||||
@@ -38,7 +38,7 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/CMSIS/Include/core_cmInstr.h)(0x5DFA0892)
|
||||
I (../Drivers/CMSIS/Include/cmsis_armcc.h)(0x5DFA0892)
|
||||
I (../Drivers/CMSIS/Include/core_cmFunc.h)(0x5DFA0892)
|
||||
I (../Drivers/CMSIS/Device/ST/STM32F0xx/Include/system_stm32f0xx.h)(0x5DFA0880)
|
||||
I (../Drivers/CMSIS/Device/ST/STM32F0xx/Include/system_stm32f0xx.h)(0x5DFA0880)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc_ex.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio.h)(0x5DFA0893)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_gpio_ex.h)(0x5DFA0893)
|
||||
@@ -111,10 +111,10 @@ I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_tim_ex.h)(0x5DFA0893)
|
||||
-IC:\Users\allen\AppData\Local\Arm\Packs\ARM\CMSIS\5.6.0\CMSIS\Core\Include
|
||||
|
||||
-IC:\Users\allen\AppData\Local\Arm\Packs\Keil\STM32F0xx_DFP\2.0.0\Drivers\CMSIS\Device\ST\STM32F0xx\Include
|
||||
|
||||
|
||||
-D__UVISION_VERSION="529" -D_RTE_ -DSTM32F042x6 -DUSE_HAL_DRIVER -DSTM32F042x6
|
||||
|
||||
-o my_adb\helpers.o --omf_browse my_adb\helpers.crf --depend my_adb\helpers.d)
|
||||
-o my_adb\helpers.o --omf_browse my_adb\helpers.crf --depend my_adb\helpers.d)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\stdio.h)(0x5D9B429A)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\string.h)(0x5D9B4298)
|
||||
I (C:\Keil_v5\ARM\ARMCC\include\stdlib.h)(0x5D9B429A)
|
||||
@@ -152,7 +152,7 @@ I (C:\Keil_v5\ARM\ARMCC\include\stdlib.h)(0x5D9B429A)
|
||||
I (../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart_ex.h)(0x5DFA0893)
|
||||
I (../Inc/shared.h)(0x617487BD)
|
||||
F (..\Inc\adb.h)(0x61D172C8)()
|
||||
F (..\Inc\delay_us.h)(0x617487C7)()
|
||||
F (..\Inc\delay_us.h)(0x617487C7)()
|
||||
F (..\Inc\helpers.h)(0x61D0D49B)()
|
||||
F (../Src/main.c)(0x61D17434)(--c99 -c --cpu Cortex-M0 -D__MICROLIB -g -O3 --apcs=interwork --split_sections -I ../Inc -I ../Drivers/STM32F0xx_HAL_Driver/Inc -I ../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I ../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I ../Drivers/CMSIS/Include
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "adb.h"
|
||||
#include "delay_us.h"
|
||||
|
||||
|
||||
GPIO_TypeDef* adb_psw_port;
|
||||
uint16_t adb_psw_pin;
|
||||
GPIO_TypeDef* adb_data_port;
|
||||
@@ -149,14 +148,13 @@ int32_t wait_until_change(int32_t timeout_us)
|
||||
uint8_t look_for_atten(void)
|
||||
{
|
||||
// if ADB data line is high
|
||||
if(ADB_READ_DATA_PIN() == GPIO_PIN_SET)
|
||||
wait_until_change(0);
|
||||
|
||||
if(ADB_READ_DATA_PIN() == GPIO_PIN_SET && wait_until_change(ADB_DEFAULT_TIMEOUT_US) == ADB_TIMEOUT)
|
||||
return ADB_TIMEOUT;
|
||||
// now data line is low
|
||||
int32_t atten_duration = wait_until_change(ADB_DEFAULT_TIMEOUT_US);
|
||||
if(atten_duration > 2000 || atten_duration == ADB_TIMEOUT)
|
||||
return ADB_LINE_STATUS_RESET;
|
||||
if(atten_duration < 600)
|
||||
if(atten_duration < 500)
|
||||
return ADB_LINE_STATUS_BUSY; // not an attention signal
|
||||
return ADB_LINE_STATUS_ATTEN;
|
||||
}
|
||||
@@ -211,21 +209,21 @@ uint8_t adb_write_byte(uint8_t data)
|
||||
if((data >> (7-i)) & 0x1)
|
||||
{
|
||||
ADB_DATA_LOW();
|
||||
delay_us(35);
|
||||
delay_us(ADB_CLK_35);
|
||||
ADB_DATA_HI();
|
||||
// if the line doesnt actually go high, then there has been a bus collision
|
||||
if(ADB_READ_DATA_PIN() != GPIO_PIN_SET)
|
||||
return ADB_LINE_STATUS_COLLISION;
|
||||
delay_us(65);
|
||||
delay_us(ADB_CLK_65);
|
||||
}
|
||||
else
|
||||
{
|
||||
ADB_DATA_LOW();
|
||||
delay_us(65);
|
||||
delay_us(ADB_CLK_65);
|
||||
ADB_DATA_HI();
|
||||
if(ADB_READ_DATA_PIN() != GPIO_PIN_SET)
|
||||
return ADB_LINE_STATUS_COLLISION;
|
||||
delay_us(35);
|
||||
delay_us(ADB_CLK_35);
|
||||
}
|
||||
}
|
||||
return ADB_OK;
|
||||
@@ -245,13 +243,13 @@ uint8_t adb_send_response_16b(uint16_t data)
|
||||
{
|
||||
delay_us(200); // stop-to-start time
|
||||
ADB_DATA_LOW();
|
||||
delay_us(35);
|
||||
delay_us(ADB_CLK_35);
|
||||
ADB_DATA_HI();
|
||||
delay_us(65);
|
||||
delay_us(ADB_CLK_65);
|
||||
if(adb_write_16(data) == ADB_LINE_STATUS_COLLISION)
|
||||
return ADB_LINE_STATUS_COLLISION;
|
||||
ADB_DATA_LOW();
|
||||
delay_us(65);
|
||||
delay_us(ADB_CLK_65);
|
||||
ADB_DATA_HI();
|
||||
return ADB_OK;
|
||||
}
|
||||
@@ -329,9 +327,7 @@ uint8_t parse_adb_cmd(uint8_t data)
|
||||
|
||||
// if(data != last_cmd)
|
||||
// {
|
||||
// DEBUG0_HI();
|
||||
// printf("%x %x\n", data, adb_mouse_current_addr);
|
||||
// DEBUG0_LOW();
|
||||
// last_cmd = data;
|
||||
// }
|
||||
|
||||
|
||||
@@ -55,7 +55,6 @@
|
||||
|
||||
#define IS_ADB_DEVICE_PRESENT() HAL_GPIO_ReadPin(ADB_5V_DET_GPIO_Port, ADB_5V_DET_Pin)
|
||||
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
@@ -154,11 +153,45 @@ void handle_protocol_switch(uint8_t spi_byte)
|
||||
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, GPIO_PIN_SET);
|
||||
memcpy(backup_spi1_recv_buf, spi_recv_buf, SPI_BUF_SIZE);
|
||||
|
||||
if(backup_spi1_recv_buf[0] != 0xde)
|
||||
{
|
||||
if(spi_recv_buf[0] != 0xde)
|
||||
spi_error_occured = 1;
|
||||
memcpy(backup_spi1_recv_buf, spi_recv_buf, SPI_BUF_SIZE);
|
||||
HAL_SPI_TransmitReceive_IT(&hspi1, spi_transmit_buf, spi_recv_buf, SPI_BUF_SIZE);
|
||||
HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void spi_error_dump_reboot(void)
|
||||
{
|
||||
printf("SPI ERROR\n");
|
||||
for (int i = 0; i < SPI_BUF_SIZE; ++i)
|
||||
printf("%d ", backup_spi1_recv_buf[i]);
|
||||
printf("\nrebooting...\n");
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
HAL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin);
|
||||
HAL_Delay(100);
|
||||
}
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
const char boot_message[] = "USB4VC Protocol Board\nApple Desktop Bus (ADB)\ndekuNukem 2022";
|
||||
|
||||
void protocol_status_lookup_init(void)
|
||||
{
|
||||
memset(protocol_status_lookup, PROTOCOL_STATUS_NOT_AVAILABLE, PROTOCOL_LOOKUP_SIZE);
|
||||
protocol_status_lookup[PROTOCOL_ADB_KB] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_status_lookup[PROTOCOL_ADB_MOUSE] = PROTOCOL_STATUS_ENABLED;
|
||||
}
|
||||
|
||||
void process_spi_data(void)
|
||||
{
|
||||
if(backup_spi1_recv_buf[0] == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if(spi_error_occured)
|
||||
{
|
||||
spi_error_dump_reboot();
|
||||
}
|
||||
else if(backup_spi1_recv_buf[SPI_BUF_INDEX_MSG_TYPE] == SPI_MOSI_MSG_TYPE_KEYBOARD_EVENT)
|
||||
{
|
||||
@@ -212,42 +245,14 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
handle_protocol_switch(backup_spi1_recv_buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
HAL_SPI_TransmitReceive_IT(&hspi1, spi_transmit_buf, spi_recv_buf, SPI_BUF_SIZE);
|
||||
HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, GPIO_PIN_RESET);
|
||||
memset(backup_spi1_recv_buf, 0, SPI_BUF_SIZE);
|
||||
}
|
||||
|
||||
void spi_error_dump_reboot(void)
|
||||
{
|
||||
printf("SPI ERROR\n");
|
||||
for (int i = 0; i < SPI_BUF_SIZE; ++i)
|
||||
printf("%d ", backup_spi1_recv_buf[i]);
|
||||
printf("\nrebooting...\n");
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
HAL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin);
|
||||
HAL_Delay(100);
|
||||
}
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
const char boot_message[] = "USB4VC Protocol Board\nApple Desktop Bus (ADB)\ndekuNukem 2022";
|
||||
|
||||
void protocol_status_lookup_init(void)
|
||||
{
|
||||
memset(protocol_status_lookup, PROTOCOL_STATUS_NOT_AVAILABLE, PROTOCOL_LOOKUP_SIZE);
|
||||
protocol_status_lookup[PROTOCOL_ADB_KB] = PROTOCOL_STATUS_ENABLED;
|
||||
protocol_status_lookup[PROTOCOL_ADB_MOUSE] = PROTOCOL_STATUS_ENABLED;
|
||||
}
|
||||
uint32_t last_send;
|
||||
void adb_mouse_update(void)
|
||||
{
|
||||
mouse_event* this_mouse_event = mouse_buf_peek(&my_mouse_buf);
|
||||
if(this_mouse_event == NULL)
|
||||
return;
|
||||
|
||||
// printf("%d %d\n", this_mouse_event->movement_x, this_mouse_event->movement_y);
|
||||
|
||||
uint16_t response = 0;
|
||||
if(this_mouse_event->button_left == 0)
|
||||
response |= 0x8000;
|
||||
@@ -256,15 +261,10 @@ void adb_mouse_update(void)
|
||||
response |= ((uint8_t)(this_mouse_event->movement_x)) & 0x7f;
|
||||
response |= (((uint8_t)(this_mouse_event->movement_y)) & 0x7f) << 8;
|
||||
|
||||
if(0 || HAL_GetTick() - last_send > 300)
|
||||
{
|
||||
DEBUG1_HI();
|
||||
adb_send_response_16b(0x8080);
|
||||
// printf("0x%x\n", response);
|
||||
DEBUG1_LOW();
|
||||
last_send = HAL_GetTick();
|
||||
}
|
||||
|
||||
DEBUG1_HI();
|
||||
adb_send_response_16b(response);
|
||||
DEBUG1_LOW();
|
||||
printf("%d %d\n", this_mouse_event->movement_x, this_mouse_event->movement_y);
|
||||
mouse_buf_reset(&my_mouse_buf);
|
||||
}
|
||||
|
||||
@@ -319,30 +319,25 @@ int main(void)
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
|
||||
DEBUG0_HI();
|
||||
process_spi_data();
|
||||
DEBUG0_LOW();
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
||||
if(IS_ADB_DEVICE_PRESENT() == 0)
|
||||
continue;
|
||||
adb_status = adb_recv_cmd(&adb_data, 0);
|
||||
// printf("%d\n", adb_status);
|
||||
|
||||
if(adb_status == ADB_LINE_STATUS_RESET)
|
||||
adb_reset();
|
||||
else if(adb_status != ADB_OK)
|
||||
continue;
|
||||
// printf("%d\n", adb_data);
|
||||
|
||||
adb_status = parse_adb_cmd(adb_data);
|
||||
|
||||
if(adb_status == ADB_MOUSE_POLL)
|
||||
{
|
||||
adb_mouse_update();
|
||||
}
|
||||
// if(adb_status == ADB_KB_POLL)
|
||||
// {
|
||||
// DEBUG0_HI();
|
||||
// DEBUG0_LOW();
|
||||
// }
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
|
||||
|
||||
@@ -1,3 +1,31 @@
|
||||
while (1)
|
||||
{
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
||||
adb_status = adb_recv_cmd(&adb_data, 0);
|
||||
// printf("%d\n", adb_status);
|
||||
|
||||
if(adb_status == ADB_LINE_STATUS_RESET)
|
||||
adb_reset();
|
||||
else if(adb_status != ADB_OK)
|
||||
continue;
|
||||
// printf("%d\n", adb_data);
|
||||
adb_status = parse_adb_cmd(adb_data);
|
||||
|
||||
if(adb_status == ADB_MOUSE_POLL)
|
||||
{
|
||||
adb_mouse_update();
|
||||
}
|
||||
// if(adb_status == ADB_KB_POLL)
|
||||
// {
|
||||
// DEBUG0_HI();
|
||||
// DEBUG0_LOW();
|
||||
// }
|
||||
}
|
||||
|
||||
adb_status = adb_recv_cmd(&adb_data, 0);
|
||||
// if(cmd == ADB_CMD_TYPE_TALK && reg == 0 && addr == adb_mouse_current_addr && HAL_GetTick() - last_send > 500)
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user