Commit Graph

1583 Commits (5bcec224409747fd03d931691b6fa737d571c671)

Author SHA1 Message Date
Purdea Andrei 338a1506dc tmk_core/common/timer.h: Fixing TIMER_DIFF macro to calculate difference correctly after the timer wraps.
Let's go through an example, using the following macro:

If the first timer read is 0xe4 and the second one is 0x32, the timer wrapped.
If the timer would have had more bits, it's new value would have been 0x132,
and the correct difference in time is 0x132 - 0xe4 = 0x4e

old code TIMER_DIFF_8(0x32, 0xe4) = 0xff - 0xe4 + 0x32 = 0x4d, which is wrong.
new code TIMER_DIFF_8(0x32, 0xe4) = 0xff + 1 - 0xe4 + 0x32 = 0x4e, which is correct.

This also gives a chance for a smart compiler to optimize the code using normal
integer overflow.

For example on AVR, the following C code:
uint8_t __attribute__ ((noinline)) test(uint8_t current_timer, uint8_t start_timer)
{
    return TIMER_DIFF_8(current_timer, start_timer);
}
With the original code, it gets translated to the following list of instructions:
00004c6e <test>:
    4c6e:       98 2f           mov     r25, r24
    4c70:       86 1b           sub     r24, r22
    4c72:       96 17           cp      r25, r22
    4c74:       08 f4           brcc    .+2             ; 0x4c78 <test+0xa>
    4c76:       81 50           subi    r24, 0x01       ; 1
    4c78:       08 95           ret
But with this commit, it gets translated to a single instruction:
00004c40 <test>:
    4c40:       86 1b           sub     r24, r22
    4c42:       08 95           ret

This unfortunately doesn't always work so nicely, for example the following C code:
int __attribute__ ((noinline)) test(uint8_t current_timer, uint8_t start_timer)
{
    return TIMER_DIFF_8(current_timer, start_timer);
}
(Note: return type changed to int)
With the original code it gets translated to:
00004c6e <test>:
    4c6e:       28 2f           mov     r18, r24
    4c70:       30 e0           ldi     r19, 0x00       ; 0
    4c72:       46 2f           mov     r20, r22
    4c74:       50 e0           ldi     r21, 0x00       ; 0
    4c76:       86 17           cp      r24, r22
    4c78:       20 f0           brcs    .+8             ; 0x4c82 <test+0x14>
    4c7a:       c9 01           movw    r24, r18
    4c7c:       84 1b           sub     r24, r20
    4c7e:       95 0b           sbc     r25, r21
    4c80:       08 95           ret
    4c82:       c9 01           movw    r24, r18
    4c84:       84 1b           sub     r24, r20
    4c86:       95 0b           sbc     r25, r21
    4c88:       81 50           subi    r24, 0x01       ; 1
    4c8a:       9f 4f           sbci    r25, 0xFF       ; 255
    4c8c:       08 95           ret
Wth this commit it gets translated to:
00004c40 <test>:
    4c40:       28 2f           mov     r18, r24
    4c42:       30 e0           ldi     r19, 0x00       ; 0
    4c44:       46 2f           mov     r20, r22
    4c46:       50 e0           ldi     r21, 0x00       ; 0
    4c48:       86 17           cp      r24, r22
    4c4a:       20 f0           brcs    .+8             ; 0x4c54 <test+0x14>
    4c4c:       c9 01           movw    r24, r18
    4c4e:       84 1b           sub     r24, r20
    4c50:       95 0b           sbc     r25, r21
    4c52:       08 95           ret
    4c54:       c9 01           movw    r24, r18
    4c56:       84 1b           sub     r24, r20
    4c58:       95 0b           sbc     r25, r21
    4c5a:       93 95           inc     r25
    4c5c:       08 95           ret
There is not much performance improvement in this case, however at least with this
commit it functions correctly.

Note: The following commit will improve compiler output for the latter example.
2020-04-01 07:45:05 +03:00
tmk 8f86d125c3 ibmpc_usb: Update firmware hex files 2020-03-22 21:30:22 +09:00
tmk fefe1028de ibmpc_usb: Add comment on INTERRUPT_CONTROL_ENDPOINT 2020-03-20 14:43:52 +09:00
tmk a7ccdc25b1 lufa: Add comment on INTERRUPT_CONTROL_ENDPOINT
This feature can block other executions and prevents converter
from handling signal.
2020-03-20 14:34:44 +09:00
tmk ab16474335 lufa: Disable SOF interrupt
The interrupt takes 3us every 1ms and can prevent
signal handling of ibmpc converter.
2020-03-20 12:46:48 +09:00
tmk 4df25c2618 fc660c: Update firmware hex files 2020-03-13 13:51:50 +09:00
tmk a4d4f14942 ibmpc_usb: Fix CS3 scan code in comment 2020-03-04 08:02:16 +09:00
tmk f99d1b12e7 ibmpc_usb: Update README 2020-03-02 14:44:39 +09:00
tmk 4052955535 Merge branch 'ibmpc_update' 2020-03-02 14:36:38 +09:00
tmk c7160e29bb ibmpc_usb: Update firmware binary 2020-03-02 14:33:25 +09:00
tmk f9fb97707f ibmpc_usb: Change keymap for application key 2020-03-02 14:21:54 +09:00
tmk f8685ce694 ibmpc: Fix debug print 2020-03-02 14:11:16 +09:00
tmk 8e7027f115 ibmpc_usb: Check overrun error for CS2 and CS3 2020-03-02 14:10:27 +09:00
tmk 28cd55c1bf ibmpc_usb: Check invalid code for CS1 2020-03-02 14:09:34 +09:00
tmk 2c9ae5ac95 ibmpc: Protocol detection between AT and XT 2020-03-02 11:04:30 +09:00
tmk 0481aa08e5 ibmpc: Check buffer full and error code FF 2020-03-02 01:48:11 +09:00
tmk 0b1fbeb135 ibmpc: Fix comments 2020-03-02 01:21:04 +09:00
tmk b7412f6228 ibmpc: Add timeout check 2020-03-02 00:14:09 +09:00
tmk c023e5feea ibmpc_usb: Wait BAT(AA) code forever 2020-03-01 23:33:29 +09:00
tmk 0c80bfca71 ibmpc_usb: Error recovery with invalid scan code 2020-03-01 23:23:55 +09:00
tmk 2f640de68d ibmpc: Refactor code 2020-02-29 17:29:55 +09:00
tmk 4588ae8dac ibmpc: Fix debug print and wait time 2020-02-29 17:29:55 +09:00
tmk 83ebf5212d ibmpc_usb: Fix init code not to block main loop
blocking loop prevents console output at startup
2020-02-29 17:29:55 +09:00
tmk 9acc900ffb ibmpc: Add two-byte buffer for data received 2020-02-29 17:29:55 +09:00
tmk e89ade52e1 ibmpc: Fix stop bit check code in ISR
removing function call makes prologue/epilogue shorter
2020-02-29 17:29:55 +09:00
tmk a42cc4bddb ibmpc_usb: Fix hard reset code 2020-02-29 17:29:55 +09:00
tmk c2e8c0d43e ibmpc: Change ISR code
It reads data line within 3us
2020-02-29 17:29:54 +09:00
tmk e7d6d24c17 ibm_usb: Fix interrupt enable macro
clear interrupt flag before enabling to ditch unwanted interrupt
2020-02-29 17:29:54 +09:00
tmk 9a06c701b0 ibmpc_usb: Fix keyboard initialize 2020-02-29 17:29:54 +09:00
tmk 15ab461f44 ibmpc: Add ibmpc_host_clear_isr 2020-02-29 17:29:54 +09:00
tmk b2fb5b715c ibmpc: Add intruppt disable and enable function 2020-02-29 17:29:54 +09:00
tmk cb026d74a5 ibmpc_usb: Fix Disable/Enable keyboard
- Return without enabling with F4 for 84-key AT wrongly before this fix
- disable/enable doesn't seems to be needed
2020-02-29 17:29:54 +09:00
tmk 7587fe3382 ibmpc: Fix how to initialize keyboard 2020-02-29 17:29:54 +09:00
tmk f68a1f5590 ibmpc: Fix error handling for keyobard hotswap 2020-02-29 17:29:54 +09:00
tmk f7b74361a0 ibmpc: Fix START case in ISR 2020-02-29 17:29:54 +09:00
tmk 3e2900dcc8 ibmpc: Read data line earlier in ISR as possible 2020-02-29 17:29:54 +09:00
tmk fc4b6cd341 adb_usb: Update prebuilt firmware 2020-02-13 09:04:44 +09:00
tmk ce5e565f58 adb_usb: Fix start up delay for AEK/AEKII
Without proper delay keyboard the converter starts talking too early
before keyboard wakes up. ISO recognition and enabling Extention protocol
would be failed in the result.
https://github.com/tmk/tmk_keyboard/issues/640#issuecomment-585411393
200ms is enough for AEKs but 1000ms is used here for safety.
2020-02-13 08:49:09 +09:00
tmk 6209ceebfb lufa: Rename LUFA_DEBUG to TMK_LUFA_DEBUG 2020-02-09 21:17:52 +09:00
tmk ea1d7ff240 lufa: Update makefile for new LUFA 2020-02-09 21:04:43 +09:00
tmk 28662f2978 lufa: Use the latest LUFA library on github 2020-02-09 21:03:49 +09:00
tmk 4726938779 lufa: Remove old LUFA directory 2020-02-09 21:03:04 +09:00
tmk 91a125baeb lufa: Fix console_putc
buffering before host and hid_listen become ready
2020-02-09 20:53:45 +09:00
tmk a4abe50f18 adb_usb: Fix mouse init and debug print 2020-02-09 20:47:04 +09:00
tmk 3b7bf1f6e0 usb_usb: Fix unimap translation for Power 2020-02-03 12:47:05 +09:00
tmk 01477b7ef2 core: Fix unimap translation range 2020-02-03 12:47:01 +09:00
tmk 3b21f85e9b alps64: Update prebuilt firmware 2019-12-28 22:57:22 +09:00
tmk ba4f28a484 alps64: Fix for delay time for matrix scan
Delay less than 20us can cause false key detection in some situations.
With week internal pull-up takes time to charge stray capacitance of
trace between ground fill(and fingers), perhaps?

In particular, when testing Alps64 PCB without diodes tweezer is used
to close a key and this makes trace longer, more capacitance in result.
2019-12-28 22:54:37 +09:00
tmk 45e45691e0 ibmpc_usb: Add prebuilt firmware files 2019-12-05 09:07:14 +09:00
tmk 5a759850ff ibmpc_usb: Fix Makefiles 2019-12-05 08:57:41 +09:00