aboutsummaryrefslogtreecommitdiff
path: root/gpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'gpio.c')
-rw-r--r--gpio.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/gpio.c b/gpio.c
new file mode 100644
index 0000000..700dced
--- /dev/null
+++ b/gpio.c
@@ -0,0 +1,54 @@
+/************************************************************************/
+/* */
+/* File: gpio.c */
+/* Description: general purpose input/output driver. */
+/* Version: 1.0 */
+/* Author: Otto Mattik */
+/* */
+/* (C)Copyright Otto Mattik 2014-2021. */
+/* */
+/* This file is a part of 'armen' (a tiny operating system). */
+/* 'armen' is distributed under the CeCILL-V2.1 licence. For more */
+/* details about this licence, please visit the website cecill.info */
+/* */
+/************************************************************************/
+
+#include <stdarg.h>
+#include "armen.h"
+
+#ifdef __AVR_ARCH__
+ #define AVR_GPIO_C
+ #include "avr/gpio.c"
+#endif
+
+/*
+ * initialize a gpio pin
+ *
+ * input:
+ * gpio gpio pin
+ * mode input or output
+*/
+void gpio_pin_mode( uint8_t gpio, uint8_t mode, ... )
+{
+#ifdef CHECK_PARAM
+ if( gpio < (GPIO_MAX_PORT << 3) )
+#endif
+ {
+ if( mode == GPIO_INPUT )
+ gpio_pin_mode_input( gpio );
+ else
+#ifdef CHECK_PARAM
+ if( mode == GPIO_OUTPUT )
+#endif
+ {
+ va_list args;
+ uint8_t value;
+
+ va_start( args, mode );
+ value = (uint8_t)va_arg( args, int );
+ gpio_pin_mode_output( gpio, value );
+ va_end( args );
+ }
+ }
+}
+