leddie/firmware/lib/hal.h

52 lines
1.2 KiB
C

#ifndef _HAL_H
#define _HAL_H
#include <avr/io.h>
#define HAL_OUTPUT(name) PORT_##name(DDR) |= PIN_##name
#define HAL_INPUT(name) PORT_##name(DDR) &= ~(PIN_##name)
#define HAL_SET(name) PORT_##name(PORT) |= PIN_##name
#define HAL_CLEAR(name) PORT_##name(PORT) &= ~(PIN_##name)
#define HAL_ISHIGH(name) (PORT_##name(PIN) & PIN_##name)
#define HAL_ON(name) HAL_SET(name)
#define HAL_ON_N(name) HAL_CLEAR(name)
#define HAL_OFF(name) HAL_CLEAR(name)
#define HAL_OFF_N(name) HAL_SET(name)
#define HAL_ASSERTED(name) HAL_ISHIGH(name)
#define HAL_ASSERTED_N(name) (!HAL_ISHIGH(name))
#define HAL_INIT(name, type, default) HAL_##default(name); HAL_##type(name)
#define PORT_VBUS_SENSE(t) t##B
#define PIN_VBUS_SENSE (1 << 2)
#define PORT_VLED_EN_N(t) t##D
#define PIN_VLED_EN_N (1 << 6) // Hotfix
#define PORT_CHG_ACTIVE_N(t) t##D
#define PIN_CHG_ACTIVE_N (1 << 7) // Hotfix
#define PORT_BAT_SENSE(t) t##C
#define PIN_BAT_SENSE (1 << 0)
#define PORT_BAT_SENSE_EN_N(t) t##C
#define PIN_BAT_SENSE_EN_N (1 << 1)
#define PORT_AXL_EN(t) t##C
#define PIN_AXL_EN (3 << 2)
#define PORT_AXL_I2C(t) t##C
#define PIN_AXL_I2C (3 << 4)
#define PORT_BUTTON_N(t) t##D
#define PIN_BUTTON_N (1 << 3)
// LED pin defined in `light_ws2812.h`.
#endif