forked from am32-firmware/AM32
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
MCU specific utility functions | ||
*/ | ||
#pragma once | ||
|
||
static inline void gpio_mode_set_input(uint32_t pin, uint32_t pull_up_down) | ||
{ | ||
if (pin < 8) { | ||
const uint32_t pin4 = (pin*pin*pin*pin); | ||
input_port->cfglr &= (input_port->cfglr & ~(pin4*0xfU)) | (pin4*(GPIO_MODE_INPUT | pull_up_down)); | ||
} else { | ||
pin = (pin-8); | ||
const uint32_t pin4 = (pin*pin*pin*pin); | ||
input_port->cfghr &= (input_port->cfglr & ~(pin4*0xfU)) | (pin4*(GPIO_MODE_INPUT | pull_up_down)); | ||
} | ||
} | ||
|
||
static inline void gpio_mode_set_output(uint32_t pin, uint32_t output_mode) | ||
{ | ||
if (pin < 8) { | ||
const uint32_t pin4 = (pin*pin*pin*pin); | ||
input_port->cfglr &= (input_port->cfglr & ~(pin4*0xfU)) | (pin4*(GPIO_MODE_OUTPUT | output_mode)); | ||
} else { | ||
pin = (pin-8); | ||
const uint32_t pin4 = (pin*pin*pin*pin); | ||
input_port->cfghr &= (input_port->cfghr & ~(pin4*0xfU)) | (pin4*(GPIO_MODE_OUTPUT | output_mode)); | ||
} | ||
} | ||
|
||
static inline void gpio_set(uint32_t pin) | ||
{ | ||
input_port->scr |= pin; | ||
} | ||
|
||
static inline void gpio_clear(uint32_t pin) | ||
{ | ||
input_port->clr |= pin; | ||
} | ||
|
||
static inline bool gpio_read(uint32_t pin) | ||
{ | ||
return (input_port->idt & pin) != 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
MCU specific utility functions | ||
*/ | ||
#pragma once | ||
|
||
static inline void gpio_mode_set_input(uint32_t pin, uint32_t pull_up_down) | ||
{ | ||
const uint32_t pinsq = (pin*pin); | ||
input_port->cfgr = (input_port->cfgr & ~(pinsq * 0x3U)) | (pinsq * GPIO_MODE_INPUT); | ||
input_port->pull = (input_port->pull & ~(pinsq * 0x3U)) | (pinsq * pull_up_down); | ||
} | ||
|
||
static inline void gpio_mode_set_output(uint32_t pin, uint32_t output_mode) | ||
{ | ||
const uint32_t pinsq = (pin*pin); | ||
input_port->cfgr &= (input_port->cfgr & ~(pinsq * 0x3U)) | (pinsq * GPIO_MODE_OUTPUT); | ||
input_port->omode = (input_port->omode & ~pin) | (output_mode | pin); | ||
} | ||
|
||
static inline void gpio_set(uint32_t pin) | ||
{ | ||
input_port->scr |= pin; | ||
} | ||
|
||
static inline void gpio_clear(uint32_t pin) | ||
{ | ||
input_port->clr |= pin; | ||
} | ||
|
||
static inline bool gpio_read(uint32_t pin) | ||
{ | ||
return (input_port->idt & pin) != 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters