Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/ibutton.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'ibutton.h')
-rw-r--r--ibutton.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/ibutton.h b/ibutton.h
new file mode 100644
index 0000000..e078304
--- /dev/null
+++ b/ibutton.h
@@ -0,0 +1,61 @@
+#include "defines.h"
+
+#define GLUE(a,b) a##b
+#define DDR(p) GLUE(DDR,p)
+#define PORT(p) GLUE(PORT,p)
+#define PIN(p) GLUE(PIN,p)
+
+#define LED1_DDR DDR(LED_TOP_PORT)
+#define LED2_DDR DDR(LED_TOP_RIGHT_PORT)
+#define LED3_DDR DDR(LED_BOTTOM_RIGHT_PORT)
+#define LED4_DDR DDR(LED_BOTTOM_PORT)
+#define LED5_DDR DDR(LED_BOTTOM_LEFT_PORT)
+#define LED6_DDR DDR(LED_TOP_LEFT_PORT)
+#define LED7_DDR DDR(LED_CENTER_PORT)
+#define LED1_PORT PORT(LED_TOP_PORT)
+#define LED2_PORT PORT(LED_TOP_RIGHT_PORT)
+#define LED3_PORT PORT(LED_BOTTOM_RIGHT_PORT)
+#define LED4_PORT PORT(LED_BOTTOM_PORT)
+#define LED5_PORT PORT(LED_BOTTOM_LEFT_PORT)
+#define LED6_PORT PORT(LED_TOP_LEFT_PORT)
+#define LED7_PORT PORT(LED_CENTER_PORT)
+#define LED1_PIN LED_TOP_PIN
+#define LED2_PIN LED_TOP_RIGHT_PIN
+#define LED3_PIN LED_BOTTOM_RIGHT_PIN
+#define LED4_PIN LED_BOTTOM_PIN
+#define LED5_PIN LED_BOTTOM_LEFT_PIN
+#define LED6_PIN LED_TOP_LEFT_PIN
+#define LED7_PIN LED_CENTER_PIN
+
+#define BUTTON_DDR DDR(BUTTON_PORT)
+#define BUTTON_OUT PORT(BUTTON_PORT)
+#define BUTTON_IN PIN(BUTTON_PORT)
+#define USB_DETECT_DDR DDR(USB_DETECT_PORT)
+#define USB_DETECT_OUT PORT(USB_DETECT_PORT)
+#define USB_DETECT_IN PIN(USB_DETECT_PORT)
+
+#define LINE_ENABLE_DDR DDR(LINE_ENABLE_PORT)
+#define LINE_ENABLE_OUT PORT(LINE_ENABLE_PORT)
+#define LINE_ENABLE_IN PIN(LINE_ENABLE_PORT)
+
+#define CYFRAL_PULLUP_DDR DDR(CYFRAL_PULLUP_PORT)
+#define CYFRAL_PULLUP_OUT PORT(CYFRAL_PULLUP_PORT)
+#define CYFRAL_PULLUP_IN PIN(CYFRAL_PULLUP_PORT)
+
+#define CYFRAL_REFERENCE_DDR DDR(CYFRAL_REFERENCE_PORT)
+#define CYFRAL_REFERENCE_OUT PORT(CYFRAL_REFERENCE_PORT)
+#define CYFRAL_REFERENCE_IN PIN(CYFRAL_REFERENCE_PORT)
+
+#define LINE_ENABLE set_bit(LINE_ENABLE_OUT, LINE_ENABLE_PIN)
+#define LINE_DISABLE unset_bit(LINE_ENABLE_OUT, LINE_ENABLE_PIN)
+#define CYFRAL_PULLUP_ENABLE { set_bit(CYFRAL_PULLUP_OUT, CYFRAL_PULLUP_PIN); set_bit(CYFRAL_PULLUP_DDR, CYFRAL_PULLUP_PIN); }
+#define CYFRAL_PULLUP_DISABLE { unset_bit(CYFRAL_PULLUP_DDR, CYFRAL_PULLUP_PIN); unset_bit(CYFRAL_PULLUP_OUT, CYFRAL_PULLUP_PIN); }
+#define CYFRAL_REFERENCE_ENABLE set_bit(CYFRAL_REFERENCE_OUT, CYFRAL_REFERENCE_PIN)
+#define CYFRAL_REFERENCE_DISABLE unset_bit(CYFRAL_REFERENCE_OUT, CYFRAL_REFERENCE_PIN)
+
+#define BUTTON_PRESSED !(BUTTON_IN & (1<<BUTTON_PIN))
+#define USB_POWERED !(USB_DETECT_IN & (1<<USB_DETECT_PIN))
+
+void set_leds(unsigned char leds_mask);
+void update_leds(void);
+void speedup_leds(void); \ No newline at end of file