X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=protocol%2Fps2_busywait.c;h=05dd7b27e695762cb50e0befadc60395e6a1ca3f;hb=0c95282d3d6d1d9158a8b29b25b96609869adb0c;hp=1e2925889576df5bc089fd9232b9af8fdf4d2d89;hpb=9ae9742ac59b18cf989370f53d669daeb75bd7a3;p=tmk_firmware.git diff --git a/protocol/ps2_busywait.c b/protocol/ps2_busywait.c index 1e29258..05dd7b2 100644 --- a/protocol/ps2_busywait.c +++ b/protocol/ps2_busywait.c @@ -35,16 +35,16 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* + * PS/2 protocol busywait version + */ + #include #include #include "ps2.h" #include "debug.h" -/* - * PS/2 protocol busywait version - */ - #define WAIT(stat, us, err) do { \ if (!wait_##stat(us)) { \ ps2_error = err; \ @@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE. } \ } while (0) + uint8_t ps2_error = PS2_ERR_NONE; @@ -65,18 +66,19 @@ void ps2_host_init(void) uint8_t ps2_host_send(uint8_t data) { - uint8_t res = 0; bool parity = true; ps2_error = PS2_ERR_NONE; + /* terminate a transmission if we have */ inhibit(); - _delay_us(200); // at least 100us + _delay_us(100); // 100us [4]p.13, [5]p.50 - /* start bit [1] */ + /* 'Request to Send' and Start bit */ data_lo(); clock_hi(); - WAIT(clock_lo, 20000, 10); // may take 15ms at most until device starts clocking - /* data [2-9] */ + WAIT(clock_lo, 10000, 10); // 10ms [5]p.50 + + /* Data bit */ for (uint8_t i = 0; i < 8; i++) { _delay_us(15); if (data&(1< PS2_ERR_STARTBIT3) { - printf("x%02X\n", ps2_error); + xprintf("x%02X\n", ps2_error); } inhibit(); return 0; } + +/* send LED state to keyboard */ +void ps2_host_set_led(uint8_t led) +{ + ps2_host_send(0xED); + ps2_host_send(led); +}