aboutsummaryrefslogtreecommitdiff
path: root/include/kern
diff options
context:
space:
mode:
Diffstat (limited to 'include/kern')
-rw-r--r--include/kern/common.h1
-rw-r--r--include/kern/exti/exti_manager.h32
-rw-r--r--include/kern/gpio/gpio_manager.h56
-rw-r--r--include/kern/mem.h2
4 files changed, 64 insertions, 27 deletions
diff --git a/include/kern/common.h b/include/kern/common.h
index 021229b..0acc9d3 100644
--- a/include/kern/common.h
+++ b/include/kern/common.h
@@ -39,6 +39,7 @@ typedef enum { ENDIANNESS_LITTLE, ENDIANNESS_BIG } endianness_t;
#define ptr2reg(ptr) ((uint32_t)(ptrdiff_t)(ptr))
typedef __IO uint32_t bits_t;
+typedef uint16_t msize_t;
#define regset(reg, mask, val) ((reg) = ((reg) & ~mask) | (val << CTZ(mask)))
diff --git a/include/kern/exti/exti_manager.h b/include/kern/exti/exti_manager.h
new file mode 100644
index 0000000..aa39b4f
--- /dev/null
+++ b/include/kern/exti/exti_manager.h
@@ -0,0 +1,32 @@
+#ifndef _KERN_EXTI_EXTI_MANAGER_H_
+#define _KERN_EXTI_EXTI_MANAGER_H_
+
+#include "kern/common.h"
+#include "kern/gpio/gpio_manager.h"
+#include "shared/linked_list.h"
+
+#define EXTI_ERROR_ALREADY_IN_USE 1
+
+struct EXTI_HANDLE;
+
+
+typedef struct {
+ void (*fn)(struct EXTI_HANDLE, void*);
+ void* closure;
+} exti_callback_t;
+
+LINKED_LIST_DECL(exti_callback_t);
+typedef struct EXTI_HANDLE {
+ uint8_t id;
+ linked_list_t(exti_callback_t)* callbacks;
+} exti_handle_t;
+
+exti_handle_t* enable_exti_for_gpio(gpio_pin_t gpio_pin, int* ec);
+
+exti_handle_t* exti_add_callback(exti_handle_t*, exti_callback_t* callback);
+
+gpio_pin_t exti_gpio_pin(exti_handle_t* handle);
+
+
+
+#endif /* _KERN_EXTI_EXTI_MANAGER_H_ */
diff --git a/include/kern/gpio/gpio_manager.h b/include/kern/gpio/gpio_manager.h
index 922a423..cb61059 100644
--- a/include/kern/gpio/gpio_manager.h
+++ b/include/kern/gpio/gpio_manager.h
@@ -1,8 +1,8 @@
#ifndef KERN_GPIO_GPIO_MANAGE_H_
#define KERN_GPIO_GPIO_MANAGE_H_
-#include "kern/common.h"
#include "arch/stm32l4xxx/peripherals/gpio.h"
+#include "kern/common.h"
#define GPIO_ERROR_IN_USE 1
#define GPIO_ERROR_INVALID_PIN_FOR_ALTERNATE_FUNCTION 2
@@ -10,8 +10,7 @@
typedef enum {
/* Creates vaules GPIO_PIN_<port><num> i.e. GPIO_PIN_A0 */
-#define PORT(p, pn) \
- GPIO_PIN_P ## p ## pn,
+#define PORT(p, pn) GPIO_PIN_P##p##pn,
#include "arch/stm32l4xxx/peripherals/tables/stm32l432xx/gpio/port_table.inc"
#undef PORT
@@ -20,16 +19,14 @@ typedef enum {
/* Alternate functions. */
typedef enum {
-#define AFN(fn, ...) \
- GPIO_ALTERNATE_FUNCTION_ ## fn,
+#define AFN(fn, ...) GPIO_ALTERNATE_FUNCTION_##fn,
#include "arch/stm32l4xxx/peripherals/tables/stm32l432xx/gpio/afn_table.inc"
#undef AFN
GPIO_ALTERNATE_FUNCTION_EVENTOUT,
} gpio_alternate_function_t;
#define gpio_pin_for_alternate_function(af) ((af) / 16)
-#define gpio_pin_out_of_range(pin) \
- ((pin) < 0 || (pin) >= N_GPIO_PINS)
+#define gpio_pin_out_of_range(pin) ((pin) < 0 || (pin) >= N_GPIO_PINS)
typedef enum {
GPIO_PORT_A,
@@ -83,41 +80,43 @@ typedef enum {
inline static gpio_port_t get_port_for_pin(gpio_pin_t pin)
{
switch (pin) {
-#define PORT(p, pn) \
- case GPIO_PIN_P ## p ## pn: return GPIO_PORT_ ## p;
+#define PORT(p, pn) \
+ case GPIO_PIN_P##p##pn: \
+ return GPIO_PORT_##p;
#include "arch/stm32l4xxx/peripherals/tables/stm32l432xx/gpio/port_table.inc"
#undef PORT
- case N_GPIO_PINS: return N_GPIO_PORTS;
+ case N_GPIO_PINS:
+ return N_GPIO_PORTS;
}
/* Should be unreachable. */
}
-#define DEFAULT_GPIO_OPTS_OUTPUT \
- (gpio_pin_opts_t) { \
- .mode = GPIO_MODE_OUTPUT, \
- .pull_dir = GPIO_PULL_DIR_DOWN, \
- .output_opts.speed = GPIO_OUTPUT_SPEED_MEDIUM, \
- .output_opts.type = GPIO_OUTPUT_TYPE_PUSH_PULL, \
+#define DEFAULT_GPIO_OPTS_OUTPUT \
+ (gpio_pin_opts_t) \
+ { \
+ .mode = GPIO_MODE_OUTPUT, .pull_dir = GPIO_PULL_DIR_DOWN, \
+ .output_opts.speed = GPIO_OUTPUT_SPEED_MEDIUM, \
+ .output_opts.type = GPIO_OUTPUT_TYPE_PUSH_PULL, \
}
-#define DEFAULT_GPIO_OPTS_INPUT \
- (gpio_pin_opts_t) { \
- .mode = GPIO_MODE_OUTPUT, \
- .pull_dir = GPIO_PULL_DIR_DOWN, \
+#define DEFAULT_GPIO_OPTS_INPUT \
+ (gpio_pin_opts_t) \
+ { \
+ .mode = GPIO_MODE_INPUT, .pull_dir = GPIO_PULL_DIR_DOWN, \
}
typedef struct {
- gpio_mode_t mode;
- gpio_pull_dir_t pull_dir;
+ gpio_mode_t mode;
+ gpio_pull_dir_t pull_dir;
union {
struct {
} input_opts;
struct {
- gpio_output_speed_t speed;
- gpio_output_type_t type;
+ gpio_output_speed_t speed;
+ gpio_output_type_t type;
} output_opts;
struct {
@@ -171,9 +170,7 @@ gpio_reserved_pin_t reserve_gpio_pin(
*
*/
gpio_reserved_pin_t gpio_enable_alternate_function(
- gpio_alternate_function_t fn,
- gpio_pin_t hint,
- int* error_out);
+ gpio_alternate_function_t fn, gpio_pin_t hint, int* error_out);
/*
* Releases the GPIO pin so it can be reserved again in the future.
@@ -184,4 +181,9 @@ gpio_reserved_pin_t gpio_enable_alternate_function(
*/
void release_gpio_pin(gpio_reserved_pin_t gpio_pin);
+/*
+ * Returns whether the GPIO pin has high or low input.
+ */
+bool get_gpio_pin_input_state(gpio_reserved_pin_t pin);
+
#endif /* KERN_GPIO_GPIO_MANAGE_H_ */
diff --git a/include/kern/mem.h b/include/kern/mem.h
index 20b09bb..bc6c4e2 100644
--- a/include/kern/mem.h
+++ b/include/kern/mem.h
@@ -22,6 +22,8 @@ int debug_kalloc_assert_consistency(char* error, size_t len);
void debug_print_blocks();
+int debug_is_heap_empty();
+
#endif