Add PORT macro
And use it in the `PIN` macro
This commit is contained in:
@@ -21,8 +21,10 @@ struct gpio {
|
|||||||
#define GPIO_PORT_OFFSET (0x400U)
|
#define GPIO_PORT_OFFSET (0x400U)
|
||||||
#define GPIO(port) ((struct gpio*)(uintptr_t)(GPIO_BASE_ADDR + (GPIO_PORT_OFFSET * port)))
|
#define GPIO(port) ((struct gpio*)(uintptr_t)(GPIO_BASE_ADDR + (GPIO_PORT_OFFSET * port)))
|
||||||
|
|
||||||
|
// Create a 8bit number from a port
|
||||||
|
#define PORT(port) (((port) - 'A') << 8)
|
||||||
// Create a 16bit number from a port and pin
|
// Create a 16bit number from a port and pin
|
||||||
#define PIN(port, num) ((((port) - 'A') << 8) | num)
|
#define PIN(port, num) (PORT(port) | num)
|
||||||
// get the lower byte from a PIN
|
// get the lower byte from a PIN
|
||||||
#define PINNUM(pin) (pin & 0b1111)
|
#define PINNUM(pin) (pin & 0b1111)
|
||||||
// get the upper byte from a PIN
|
// get the upper byte from a PIN
|
||||||
|
|||||||
Reference in New Issue
Block a user