diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cmsis/cmsis_gcc.h (renamed from include/cmsis_gcc.h) | 0 | ||||
-rw-r--r-- | include/cmsis/core_cm4.h (renamed from include/core_cm4.h) | 0 | ||||
-rw-r--r-- | include/cmsis/core_cmFunc.h (renamed from include/core_cmFunc.h) | 0 | ||||
-rw-r--r-- | include/cmsis/core_cmInstr.h (renamed from include/core_cmInstr.h) | 0 | ||||
-rw-r--r-- | include/cmsis/core_cmSimd.h (renamed from include/core_cmSimd.h) | 0 | ||||
-rw-r--r-- | include/gpio.h | 96 | ||||
-rw-r--r-- | include/heap.h | 28 | ||||
-rw-r--r-- | include/keypad.h | 24 | ||||
-rw-r--r-- | include/random.h | 13 | ||||
-rw-r--r-- | include/script.h | 9 | ||||
-rw-r--r-- | include/task.h | 6 |
11 files changed, 163 insertions, 13 deletions
diff --git a/include/cmsis_gcc.h b/include/cmsis/cmsis_gcc.h index d868f2e..d868f2e 100644 --- a/include/cmsis_gcc.h +++ b/include/cmsis/cmsis_gcc.h diff --git a/include/core_cm4.h b/include/cmsis/core_cm4.h index 01cb73b..01cb73b 100644 --- a/include/core_cm4.h +++ b/include/cmsis/core_cm4.h diff --git a/include/core_cmFunc.h b/include/cmsis/core_cmFunc.h index ca319a5..ca319a5 100644 --- a/include/core_cmFunc.h +++ b/include/cmsis/core_cmFunc.h diff --git a/include/core_cmInstr.h b/include/cmsis/core_cmInstr.h index 389084a..389084a 100644 --- a/include/core_cmInstr.h +++ b/include/cmsis/core_cmInstr.h diff --git a/include/core_cmSimd.h b/include/cmsis/core_cmSimd.h index 4d76bf9..4d76bf9 100644 --- a/include/core_cmSimd.h +++ b/include/cmsis/core_cmSimd.h diff --git a/include/gpio.h b/include/gpio.h index 524b791..46a8e15 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -1,46 +1,116 @@ +/** + * @file gpio.h + * Abstracts gpio access, makes things easier + */ + #ifndef GPIO_H_ #define GPIO_H_ #include <stm32l476xx.h> +/** + * Helps simplify gpio calls. + * @param p port, e.g. GPIOA + * @param b pin, e.g. 4 + */ #define GPIO_PORT(p, b) GPIO##p, b +/** + * Defines possible modes for a gpio pin + */ enum GPIO_MODE { - INPUT = 0, - OUTPUT, - ALTERNATE, - ANALOG + INPUT = 0, /**< digital input */ + OUTPUT, /**< digital output */ + ALTERNATE, /**< alternate function */ + ANALOG /**< analog function */ }; +/** + * Defines whether to use push-pull or open drain. + */ enum GPIO_TYPE { - PUSHPULL = 0, - OPENDRAIN + PUSHPULL = 0, /**< push-pull */ + OPENDRAIN /**< open drain */ }; +/** + * Defines the pin's speed + */ enum GPIO_SPEED { - LOW = 0, - MEDIUM, - HIGH, - VERYHIGH + LOW = 0, /**< low */ + MEDIUM, /**< medium */ + HIGH, /**< high */ + VERYHIGH /**< very high/maximum */ }; +/** + * Defines if a pullup or pulldown should be used. + */ enum GPIO_PUPD { - NOPUPD, - PULLUP, - PULLDOWN + NOPUPD, /**< no pullup/pulldown */ + PULLUP, /**< use pullup */ + PULLDOWN /**< use pulldown */ }; +/** + * Initializes the gpio. + */ void gpio_init(void); +/** + * Enables or disables pullup/pulldown for the given pin. + * @param port the port, e.g. GPIOA + * @param pin the pin + * @param pupd pullup/pulldown enable + * @see GPIO_PUPD + */ void gpio_pupd(GPIO_TypeDef *port, uint8_t pin, uint8_t pupd); + +/** + * Sets whether to use push-pull or open drain for the given pin. + * @param port the port + * @param pin the pin + * @param type what to use + * @see GPIO_TYPE + */ void gpio_type(GPIO_TypeDef *port, uint8_t pin, uint8_t type); + +/** + * Sets the pin's speed. + * @param port the port + * @param pin the pin + * @param speed the speed to use + * @see GPIO_SPEED + */ void gpio_speed(GPIO_TypeDef *port, uint8_t pin, uint8_t speed); + +/** + * Sets the pin's i/o mode. + * @param port the port + * @param pin the pin + * @param mode the mode to use + * @see GPIO_MODE + */ void gpio_mode(GPIO_TypeDef *port, uint8_t pin, uint8_t mode); + +/** + * Sets the state of a digital output pin. + * @param port the port + * @param pin the pin + * @param val non-zero for high, zero for low + */ void gpio_dout(GPIO_TypeDef *port, uint8_t pin, uint8_t val); + +/** + * Reads a digital input pin. + * @param port the port + * @param pin the pin + * @return non-zero for high, zero for low + */ uint8_t gpio_din(GPIO_TypeDef *port, uint8_t pin); #endif // GPIO_H_ diff --git a/include/heap.h b/include/heap.h index c93eb8e..e8cd9c1 100644 --- a/include/heap.h +++ b/include/heap.h @@ -1,12 +1,40 @@ +/** + * @file heap.h + * A basic memory manager + */ + #ifndef HEAP_H_ #define HEAP_H_ #include <stdint.h> +/** + * Initializes memory management of the given heap. + * No overflow stuff is done, so... + * @param buf the heap to use for allocations + */ void heap_init(void *buf); +/** + * Allocates a chunk of memory. + * @param size how many bytes to claim + * @return pointer to the allocated buffer + */ void *malloc(uint32_t size); + +/** + * Allocates and zeros a chunk of memory. + * @param count how many of whatever to allocate + * @param size byte count of each whatever + * @return pointer to the allocated buffer + */ void *calloc(uint32_t count, uint32_t size); + +/** + * Frees the buffer allocated through malloc/calloc. + * Please don't double-free. + * @param the buffer to release + */ void free(void *buf); #endif // HEAP_H_ diff --git a/include/keypad.h b/include/keypad.h new file mode 100644 index 0000000..83e0626 --- /dev/null +++ b/include/keypad.h @@ -0,0 +1,24 @@ +#ifndef KEYPAD_H_ +#define KEYPAD_H_ + +#include <stdint.h> + +#define K0 (1 << 0) +#define K1 (1 << 1) +#define K2 (1 << 2) +#define K3 (1 << 3) +#define K4 (1 << 4) +#define K5 (1 << 5) +#define K6 (1 << 6) +#define K7 (1 << 7) +#define K8 (1 << 8) +#define K9 (1 << 9) +#define KS (1 << 10) +#define KP (1 << 11) + +void keypad_init(void); + +uint16_t keypad_get(void); +uint8_t keypad_isdown(uint16_t); + +#endif // KEYPAD_H_ diff --git a/include/random.h b/include/random.h index 6485f26..a1868f6 100644 --- a/include/random.h +++ b/include/random.h @@ -1,9 +1,22 @@ +/** + * @file random.h + * Provides true random number generation functionality + */ + #ifndef RANDOM_H_ #define RANDOM_H_ #include <stdint.h> +/** + * Initializes the STM's true random number generator. + */ void random_init(void); + +/** + * Gets the next random number from the generator. + * @return the random number + */ uint32_t random_get(void); #endif // RANDOM_H_ diff --git a/include/script.h b/include/script.h index dc8c590..7901c9c 100644 --- a/include/script.h +++ b/include/script.h @@ -1,8 +1,17 @@ +/** + * @file script.h + * Provides script library for using calculator hardware + */ + #ifndef SCRIPT_H_ #define SCRIPT_H_ #include <parser.h> +/** + * Loads the library for the given interpreter. + * @param it the interpreter to use + */ void script_loadlib(interpreter *it); #endif // SCRIPT_H_ diff --git a/include/task.h b/include/task.h index 1ef8639..6456bdc 100644 --- a/include/task.h +++ b/include/task.h @@ -28,6 +28,12 @@ void task_init(void (*init)(void)); */ void task_start(void (*task)(void), uint16_t stackSize); +/** + * Allows task switching to be disabled, for low-level actions. + * Multiple holds can be placed, and all must be removed to continue task + * switching. + * @param hold non-zero for hold, zero to remove hold + */ void task_hold(uint8_t hold); #endif // TASK_H_ |