From 5d29fe79d30f430ae326d9dc57ccfaed6fe61328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 8 Mar 2016 16:10:33 +0100 Subject: Another full update of current work --- include/ioport.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 include/ioport.h (limited to 'include/ioport.h') diff --git a/include/ioport.h b/include/ioport.h new file mode 100644 index 0000000..1022493 --- /dev/null +++ b/include/ioport.h @@ -0,0 +1,55 @@ +#include +#include +#include + +#include "mcu/mcu_def.h" + +#ifndef _IOE_IOPORT_H_ +#define _IOE_IOPORT_H_ +#ifdef CONFIG_IOPORTS + +enum ioInResistor { + IO_PULLUP, + IO_PULLDOWN +}; + +static inline void io_setout(uint8_t group, uint8_t mask) { + IO_DDR(group) |= mask; +} +static inline void io_hight(uint8_t group, uint8_t mask) { + IO_PORT(group) |= mask; +} +static inline void io_low(uint8_t group, uint8_t mask) { + IO_PORT(group) &= ~mask; +} +static inline void io_set(uint8_t group, uint8_t mask, int8_t val) { + if (val) + io_hight(group, mask); + else + io_low(group, mask); +} + +static inline void io_setin(uint8_t group, uint8_t mask, + enum ioInResistor resistor) { + IO_DDR(group) &= ~mask; + if (resistor == IO_PULLUP) + IO_PORT(group) |= mask; + else + IO_PORT(group) &= ~mask; +} +static inline int8_t io_get(uint8_t group, uint8_t mask) { + return (int8_t) IO_PIN(group) & mask; +} + +#ifdef CONFIG_PCINT + +#define IO_RISING (1 << 0) +#define IO_FALLING (1 << 1) +void io_change_sethook(uint8_t group, uint8_t mask, uint8_t edge, + void (*change) (uint8_t group, uint8_t mask)); +void io_change_remhook(void (*change) (uint8_t group, uint8_t mask)); +void io_change_clearhooks(void); + +#endif /* CONFIG_PCINT */ +#endif /* CONFIG_IOPORTS */ +#endif /* _IOE_IOPORT_H_ */ -- cgit v1.2.3