summaryrefslogtreecommitdiff
path: root/protocol/ps2.h
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-07-30 14:37:05 +0900
committertmk <nobody@nowhere>2014-07-30 14:37:05 +0900
commitadbb86b1ec8b07e86ae7425374e95b82122e48a7 (patch)
tree0a02e89376f69ef975096af9490034725d8eb751 /protocol/ps2.h
parent79840c678e13f9a737f80048bc3b9c9c55e3fc77 (diff)
parenta9f5f201ad6b009675fdf16c4447033cc2ac0995 (diff)
Merge branch 'mbed' into dev
Diffstat (limited to 'protocol/ps2.h')
-rw-r--r--protocol/ps2.h65
1 files changed, 7 insertions, 58 deletions
diff --git a/protocol/ps2.h b/protocol/ps2.h
index 483eea7209..acde679cf4 100644
--- a/protocol/ps2.h
+++ b/protocol/ps2.h
@@ -39,8 +39,9 @@ POSSIBILITY OF SUCH DAMAGE.
#define PS2_H
#include <stdbool.h>
-#include <util/delay.h>
-#include <avr/io.h>
+#include "wait.h"
+#include "ps2_io.h"
+#include "print.h"
/*
* Primitive PS/2 Library for AVR
@@ -92,79 +93,27 @@ uint8_t ps2_host_recv(void);
void ps2_host_set_led(uint8_t usb_led);
-/* Check port settings for clock and data line */
-#if !(defined(PS2_CLOCK_PORT) && \
- defined(PS2_CLOCK_PIN) && \
- defined(PS2_CLOCK_DDR) && \
- defined(PS2_CLOCK_BIT))
-# error "PS/2 clock port setting is required in config.h"
-#endif
-
-#if !(defined(PS2_DATA_PORT) && \
- defined(PS2_DATA_PIN) && \
- defined(PS2_DATA_DDR) && \
- defined(PS2_DATA_BIT))
-# error "PS/2 data port setting is required in config.h"
-#endif
-
/*--------------------------------------------------------------------
* static functions
*------------------------------------------------------------------*/
-static inline void clock_lo(void)
-{
- PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT);
- PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT);
-}
-static inline void clock_hi(void)
-{
- /* input with pull up */
- PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
- PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
-}
-static inline bool clock_in(void)
-{
- PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
- PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
- _delay_us(1);
- return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT);
-}
-static inline void data_lo(void)
-{
- PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT);
- PS2_DATA_DDR |= (1<<PS2_DATA_BIT);
-}
-static inline void data_hi(void)
-{
- /* input with pull up */
- PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
- PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
-}
-static inline bool data_in(void)
-{
- PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
- PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
- _delay_us(1);
- return PS2_DATA_PIN&(1<<PS2_DATA_BIT);
-}
-
static inline uint16_t wait_clock_lo(uint16_t us)
{
- while (clock_in() && us) { asm(""); _delay_us(1); us--; }
+ while (clock_in() && us) { asm(""); wait_us(1); us--; }
return us;
}
static inline uint16_t wait_clock_hi(uint16_t us)
{
- while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
+ while (!clock_in() && us) { asm(""); wait_us(1); us--; }
return us;
}
static inline uint16_t wait_data_lo(uint16_t us)
{
- while (data_in() && us) { asm(""); _delay_us(1); us--; }
+ while (data_in() && us) { asm(""); wait_us(1); us--; }
return us;
}
static inline uint16_t wait_data_hi(uint16_t us)
{
- while (!data_in() && us) { asm(""); _delay_us(1); us--; }
+ while (!data_in() && us) { asm(""); wait_us(1); us--; }
return us;
}