mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
103 lines
3.0 KiB
Plaintext
103 lines
3.0 KiB
Plaintext
// printf("%d\n", HAL_GPIO_ReadPin(MAC_KB_DATA_GPIO_Port, MAC_KB_DATA_Pin));
|
|
// HAL_Delay(5);
|
|
// HAL_GPIO_TogglePin(MAC_KB_CLK_GPIO_Port, MAC_KB_CLK_Pin);
|
|
|
|
// int32_t ddd = calc_arr(avg_speed);
|
|
// if(ddd != 65535)
|
|
// printf("%d\n", calc_arr(avg_speed));
|
|
|
|
|
|
// return (uint16_t)(-190*speed_val + 12690); // 1, 12500 | 64, 500
|
|
int32_t result = -307*speed_val + 12807; // 1, 12500, 40, 500
|
|
if(buffered_value)
|
|
{
|
|
m0110a_cmd_buf_add(&my_m0110a_buf, 0x71);
|
|
m0110a_cmd_buf_add(&my_m0110a_buf, 0x79);
|
|
m0110a_cmd_buf_add(&my_m0110a_buf, 0x0d);
|
|
}
|
|
else
|
|
{
|
|
m0110a_cmd_buf_add(&my_m0110a_buf, 0xf1);
|
|
m0110a_cmd_buf_add(&my_m0110a_buf, 0x79);
|
|
m0110a_cmd_buf_add(&my_m0110a_buf, 0x8d);
|
|
}
|
|
|
|
uint16_t calc_arr(int32_t speed_val)
|
|
{
|
|
speed_val = abs(speed_val);
|
|
if(speed_val <= 0 || speed_val >= ARR_LOOKUP_SIZE)
|
|
return 500;
|
|
// int32_t result = -190*speed_val + 12690; // 1, 12500 | 64, 500
|
|
int32_t result = -307*speed_val + 12807; // 1, 12500, 40, 500
|
|
if (result < 500)
|
|
result = 500;
|
|
if(result > 12500)
|
|
result = 12500;
|
|
return (uint16_t)result;
|
|
}
|
|
|
|
else if(m0110a_inquiry_active && kb_buf_peek(&my_kb_buf, &buffered_code, &buffered_value) == 0)
|
|
{
|
|
if(buffered_value)
|
|
m0110a_write(0x23);
|
|
else
|
|
m0110a_write(0xa3);
|
|
kb_buf_pop(&my_kb_buf);
|
|
m0110a_inquiry_active = 0;
|
|
printf("%d\n", buffered_code);
|
|
}
|
|
|
|
#define ARR_LOOKUP_SIZE 40
|
|
const uint16_t arr_lookup[ARR_LOOKUP_SIZE] = {500, 12500, 10245, 8926, 7990, 7264, 6671, 6170, 5735, 5352, 5010, 4699, 4416, 4156, 3915, 3691, 3481, 3283, 3098, 2922, 2755, 2596, 2445, 2300, 2162, 2029, 1901, 1779, 1660, 1546, 1436, 1329, 1226, 1126, 1029, 934, 843, 754, 667, 582};
|
|
|
|
uint16_t calc_arr(int32_t speed_val)
|
|
{
|
|
return 500;
|
|
speed_val = abs(speed_val);
|
|
if(speed_val <= 0 || speed_val >= ARR_LOOKUP_SIZE)
|
|
return 500;
|
|
return arr_lookup[speed_val];
|
|
}
|
|
if(kb_buf_peek(&my_kb_buf, &buffered_code, &buffered_value) == 0)
|
|
{
|
|
printf("%d %d\n", buffered_code, buffered_value);
|
|
kb_buf_pop(&my_kb_buf);
|
|
}
|
|
|
|
uint8_t bit = 0x80;
|
|
while(bit)
|
|
{
|
|
printf("%x", bit);
|
|
bit = bit >> 1;
|
|
HAL_Delay(1);
|
|
}
|
|
while(1);
|
|
if(m0110a_get_line_status() == M0110A_LINE_HOST_REQ)
|
|
{
|
|
m0110a_read(&m0110a_host_cmd);
|
|
printf("%d\n", m0110a_host_cmd);
|
|
// while(m0110a_get_line_status() != M0110A_LINE_IDLE) // wait for computer to release data line to indicate it is ready
|
|
// ;
|
|
// HAL_Delay(1);
|
|
}
|
|
|
|
|
|
uint8_t m0110a_read(uint8_t* result)
|
|
{
|
|
uint8_t data = 0x00;
|
|
uint16_t bit = 0x01;
|
|
|
|
while (bit < 0x0100)
|
|
{
|
|
M0110A_CLK_LOW();
|
|
delay_us(CLK_LOW_HOST_TO_KB);
|
|
M0110A_CLK_HI();
|
|
delay_us(CLK_READ_DELAY_HOST_TO_KB); // "The keyboard reads the data bit 80 µs after the rising edge of the Keyboard Clock signal." page 282, Guide to Macintosh Family Hardware 2nd edition.
|
|
if(M0110A_READ_DATA_PIN() == GPIO_PIN_SET)
|
|
data = data | bit;
|
|
bit = bit << 1;
|
|
delay_us(CLK_HIGH_HOST_TO_KB - CLK_READ_DELAY_HOST_TO_KB);
|
|
}
|
|
*result = data;
|
|
return M0110A_OK;
|
|
} |