aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/ibm4704.h
blob: 618cce6be0f81ea6959300fa34a60e728fee0f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Copyright 2014 Jun WAKO <wakojun@gmail.com>
*/
#ifndef IBM4704_H
#define IBM4704_H

#define IBM4704_ERR_NONE        0
#define IBM4704_ERR_PARITY      0x70


void ibm4704_init(void);
uint8_t ibm4704_send(uint8_t data);
uint8_t ibm4704_recv_response(void);
uint8_t ibm4704_recv(void);


/* Check pin configuration */
#if !(defined(IBM4704_CLOCK_PORT) && \
      defined(IBM4704_CLOCK_PIN) && \
      defined(IBM4704_CLOCK_DDR) && \
      defined(IBM4704_CLOCK_BIT))
#   error "ibm4704 clock pin configuration is required in config.h"
#endif

#if !(defined(IBM4704_DATA_PORT) && \
      defined(IBM4704_DATA_PIN) && \
      defined(IBM4704_DATA_DDR) && \
      defined(IBM4704_DATA_BIT))
#   error "ibm4704 data pin configuration is required in config.h"
#endif


/*--------------------------------------------------------------------
 * static functions
 *------------------------------------------------------------------*/
static inline void clock_lo(void)
{
    IBM4704_CLOCK_PORT &= ~(1<<IBM4704_CLOCK_BIT);
    IBM4704_CLOCK_DDR  |=  (1<<IBM4704_CLOCK_BIT);
}
static inline void clock_hi(void)
{
    /* input with pull up */
    IBM4704_CLOCK_DDR  &= ~(1<<IBM4704_CLOCK_BIT);
    IBM4704_CLOCK_PORT |=  (1<<IBM4704_CLOCK_BIT);
}
static inline bool clock_in(void)
{
    IBM4704_CLOCK_DDR  &= ~(1<<IBM4704_CLOCK_BIT);
    IBM4704_CLOCK_PORT |=  (1<<IBM4704_CLOCK_BIT);
    _delay_us(1);
    return IBM4704_CLOCK_PIN&(1<<IBM4704_CLOCK_BIT);
}
static inline void data_lo(void)
{
    IBM4704_DATA_PORT &= ~(1<<IBM4704_DATA_BIT);
    IBM4704_DATA_DDR  |=  (1<<IBM4704_DATA_BIT);
}
static inline void data_hi(void)
{
    /* input with pull up */
    IBM4704_DATA_DDR  &= ~(1<<IBM4704_DATA_BIT);
    IBM4704_DATA_PORT |=  (1<<IBM4704_DATA_BIT);
}
static inline bool data_in(void)
{
    IBM4704_DATA_DDR  &= ~(1<<IBM4704_DATA_BIT);
    IBM4704_DATA_PORT |=  (1<<IBM4704_DATA_BIT);
    _delay_us(1);
    return IBM4704_DATA_PIN&(1<<IBM4704_DATA_BIT);
}

static inline uint16_t wait_clock_lo(uint16_t us)
{
    while (clock_in()  && us) { asm(""); _delay_us(1); us--; }
    return us;
}
static inline uint16_t wait_clock_hi(uint16_t us)
{
    while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
    return us;
}
static inline uint16_t wait_data_lo(uint16_t us)
{
    while (data_in() && us)  { asm(""); _delay_us(1); us--; }
    return us;
}
static inline uint16_t wait_data_hi(uint16_t us)
{
    while (!data_in() && us)  { asm(""); _delay_us(1); us--; }
    return us;
}

/* idle state that device can send */
static inline void idle(void)
{
    clock_hi();
    data_hi();
}

/* inhibit device to send 
 * keyboard checks Data line on start bit(Data:hi) and it stops sending if Data line is low.
 */
static inline void inhibit(void)
{
    clock_hi();
    data_lo();
}

#endif
#define STM32_PWM_TIM3_IRQ_PRIORITY 7 #define STM32_PWM_TIM4_IRQ_PRIORITY 7 #define STM32_PWM_TIM9_IRQ_PRIORITY 7 /* * SERIAL driver system settings. */ #define STM32_SERIAL_USE_USART1 FALSE #define STM32_SERIAL_USE_USART2 FALSE #define STM32_SERIAL_USE_USART3 FALSE #define STM32_SERIAL_USART1_PRIORITY 12 #define STM32_SERIAL_USART2_PRIORITY 12 #define STM32_SERIAL_USART3_PRIORITY 12 /* * SPI driver system settings. */ #define STM32_SPI_USE_SPI1 FALSE #define STM32_SPI_USE_SPI2 FALSE #define STM32_SPI_SPI1_DMA_PRIORITY 1 #define STM32_SPI_SPI2_DMA_PRIORITY 1 #define STM32_SPI_SPI1_IRQ_PRIORITY 10 #define STM32_SPI_SPI2_IRQ_PRIORITY 10 #define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure") /* * ST driver system settings. */ #define STM32_ST_IRQ_PRIORITY 8 #define STM32_ST_USE_TIMER 2 /* * UART driver system settings. */ #define STM32_UART_USE_USART1 FALSE #define STM32_UART_USE_USART2 FALSE #define STM32_UART_USE_USART3 FALSE #define STM32_UART_USART1_IRQ_PRIORITY 12 #define STM32_UART_USART2_IRQ_PRIORITY 12 #define STM32_UART_USART3_IRQ_PRIORITY 12 #define STM32_UART_USART1_DMA_PRIORITY 0 #define STM32_UART_USART2_DMA_PRIORITY 0 #define STM32_UART_USART3_DMA_PRIORITY 0 #define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure") /* * USB driver system settings. */ #define STM32_USB_USE_USB1 FALSE #define STM32_USB_LOW_POWER_ON_SUSPEND FALSE #define STM32_USB_USB1_HP_IRQ_PRIORITY 13 #define STM32_USB_USB1_LP_IRQ_PRIORITY 14 /* * WDG driver system settings. */ #define STM32_WDG_USE_IWDG FALSE #endif /* MCUCONF_H */