1 /*!
2 * \file gpio-board.c
3 *
4 * \brief Target board GPIO driver implementation
5 *
6 * \copyright Revised BSD License, see section \ref LICENSE.
7 *
8 * \code
9 * ______ _
10 * / _____) _ | |
11 * ( (____ _____ ____ _| |_ _____ ____| |__
12 * \____ \| ___ | (_ _) ___ |/ ___) _ \
13 * _____) ) ____| | | || |_| ____( (___| | | |
14 * (______/|_____)_|_|_| \__)_____)\____)_| |_|
15 * (C)2013-2017 Semtech
16 *
17 * \endcode
18 *
19 * \author Miguel Luis ( Semtech )
20 *
21 * \author Gregory Cristian ( Semtech )
22 *
23 * \author Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017
24 */
25 #include <hal_gpio.h>
26 #include <hal_ext_irq.h>
27 #include "gpio-board.h"
28
GpioMcuInit(Gpio_t * obj,PinNames pin,PinModes mode,PinConfigs config,PinTypes type,uint32_t value)29 void GpioMcuInit( Gpio_t *obj, PinNames pin, PinModes mode, PinConfigs config, PinTypes type, uint32_t value )
30 {
31 obj->pin = pin;
32
33 if( pin == NC )
34 {
35 return;
36 }
37
38 //obj->port = ( void* )GPIO_PORT( obj->pin );
39
40 if( mode == PIN_INPUT )
41 {
42 gpio_set_pin_direction( obj->pin, GPIO_DIRECTION_IN );
43 gpio_set_pin_pull_mode( obj->pin, type ); // the pull up/down need to be set after the direction for correct working
44 }
45 else // mode output
46 {
47 gpio_set_pin_direction( obj->pin, GPIO_DIRECTION_OUT );
48 }
49
50
51 // Sets initial output value
52 if( mode == PIN_OUTPUT )
53 {
54 GpioMcuWrite( obj, value );
55 }
56 }
57
GpioMcuSetContext(Gpio_t * obj,void * context)58 void GpioMcuSetContext( Gpio_t *obj, void* context )
59 {
60 obj->Context = context;
61 }
62
GpioMcuSetInterrupt(Gpio_t * obj,IrqModes irqMode,IrqPriorities irqPriority,GpioIrqHandler * irqHandler)63 void GpioMcuSetInterrupt( Gpio_t *obj, IrqModes irqMode, IrqPriorities irqPriority, GpioIrqHandler *irqHandler )
64 {
65 //ext_irq_register( obj->pin, irqHandler );
66 }
67
GpioMcuRemoveInterrupt(Gpio_t * obj)68 void GpioMcuRemoveInterrupt( Gpio_t *obj )
69 {
70 //ext_irq_register( obj->pin, NULL );
71 }
72
GpioMcuWrite(Gpio_t * obj,uint32_t value)73 void GpioMcuWrite( Gpio_t *obj, uint32_t value )
74 {
75
76 if( obj == NULL )
77 {
78 //assert_param( LMN_STATUS_ERROR );
79 while( 1 );
80 }
81 // Check if pin is not connected
82 if( obj->pin == NC )
83 {
84 return;
85 }
86 gpio_set_pin_level( obj->pin, value );
87 }
88
GpioMcuToggle(Gpio_t * obj)89 void GpioMcuToggle( Gpio_t *obj )
90 {
91 if( obj == NULL )
92 {
93 //assert_param( LMN_STATUS_ERROR );
94 while( 1 );
95 }
96
97 // Check if pin is not connected
98 if( obj->pin == NC )
99 {
100 return;
101 }
102 gpio_toggle_pin_level( obj->pin );
103 }
104
GpioMcuRead(Gpio_t * obj)105 uint32_t GpioMcuRead( Gpio_t *obj )
106 {
107 if( obj == NULL )
108 {
109 //assert_param( LMN_STATUS_ERROR );
110 while( 1 );
111 }
112 // Check if pin is not connected
113 if( obj->pin == NC )
114 {
115 return 0;
116 }
117 return ( uint32_t )gpio_get_pin_level( obj->pin );
118 }
119