Choco OS  V.0.16.9.0
Join to the chocolate world
oc_gpio.h
Go to the documentation of this file.
1 
28 #ifndef INC_DRIVERS_GPIO_OC_GPIO_H_
29 #define INC_DRIVERS_GPIO_OC_GPIO_H_
30 
31 #define DRIVER_HEADER
32 #define DRIVER_NAME GPIO
33 
34 #include <oc_driver.h>
35 #include <oc_gpio_lld.h>
36 
42 #define _________________________________________TYPES_SECTION______________________________________________________________________________
43 
44 
45 //==========================================================================================================================================
51 //==========================================================================================================================================
52 typedef enum
53 {
54  oC_GPIO_Protection_DontUnlockProtectedPins = oC_GPIO_LLD_Protection_DontUnlockProtectedPins,
55  oC_GPIO_Protection_UnlockProtectedPins = oC_GPIO_LLD_Protection_UnlockProtectedPins
57 
58 //==========================================================================================================================================
65 //==========================================================================================================================================
66 typedef enum
67 {
68  oC_GPIO_Speed_Default = oC_GPIO_LLD_Speed_Default,
69  oC_GPIO_Speed_Minimum = oC_GPIO_LLD_Speed_Minimum,
70  oC_GPIO_Speed_Medium = oC_GPIO_LLD_Speed_Medium,
71  oC_GPIO_Speed_Maximum = oC_GPIO_LLD_Speed_Maximum,
72  oC_GPIO_Speed_NumberOfElements = oC_GPIO_LLD_Speed_NumberOfElements
74 
75 //==========================================================================================================================================
81 //==========================================================================================================================================
82 typedef enum
83 {
84  oC_GPIO_Current_Default = oC_GPIO_LLD_Current_Default,
85  oC_GPIO_Current_Minimum = oC_GPIO_LLD_Current_Minimum,
86  oC_GPIO_Current_Medium = oC_GPIO_LLD_Current_Medium,
87  oC_GPIO_Current_Maximum = oC_GPIO_LLD_Current_Maximum
89 
90 //==========================================================================================================================================
96 //==========================================================================================================================================
97 typedef enum
98 {
99  oC_GPIO_Mode_Default = oC_GPIO_LLD_Mode_Default,
100  oC_GPIO_Mode_Input = oC_GPIO_LLD_Mode_Input,
101  oC_GPIO_Mode_Output = oC_GPIO_LLD_Mode_Output,
102  oC_GPIO_Mode_Alternate = oC_GPIO_LLD_Mode_Alternate
104 
105 //==========================================================================================================================================
111 //==========================================================================================================================================
112 typedef enum
113 {
114  oC_GPIO_Pull_Default = oC_GPIO_LLD_Pull_Default,
115  oC_GPIO_Pull_Up = oC_GPIO_LLD_Pull_Up,
116  oC_GPIO_Pull_Down = oC_GPIO_LLD_Pull_Down
118 
119 //==========================================================================================================================================
125 //==========================================================================================================================================
126 typedef enum
127 {
128  oC_GPIO_OutputCircuit_Default = oC_GPIO_LLD_OutputCircuit_Default ,
129  oC_GPIO_OutputCircuit_OpenDrain = oC_GPIO_LLD_OutputCircuit_OpenDrain,
130  oC_GPIO_OutputCircuit_PushPull = oC_GPIO_LLD_OutputCircuit_PushPull
132 
133 
134 //==========================================================================================================================================
140 //==========================================================================================================================================
141 typedef enum
142 {
143  oC_GPIO_IntTrigger_Default = oC_GPIO_LLD_IntTrigger_Default,
144  oC_GPIO_IntTrigger_Off = oC_GPIO_LLD_IntTrigger_Off,
145  oC_GPIO_IntTrigger_RisingEdge = oC_GPIO_LLD_IntTrigger_RisingEdge,
146  oC_GPIO_IntTrigger_FallingEdge = oC_GPIO_LLD_IntTrigger_FallingEdge,
147  oC_GPIO_IntTrigger_BothEdges = oC_GPIO_LLD_IntTrigger_BothEdges,
148  oC_GPIO_IntTrigger_HighLevel = oC_GPIO_LLD_IntTrigger_HighLevel,
149  oC_GPIO_IntTrigger_LowLevel = oC_GPIO_LLD_IntTrigger_LowLevel,
150  oC_GPIO_IntTrigger_BothLevels = oC_GPIO_LLD_IntTrigger_BothLevels
152 
153 //==========================================================================================================================================
160 //==========================================================================================================================================
161 typedef enum
162 {
163  oC_GPIO_PinsState_AllLow = oC_GPIO_LLD_PinsState_AllLow,
164  oC_GPIO_PinsState_AllHigh = oC_GPIO_LLD_PinsState_AllHigh
166 
167 //==========================================================================================================================================
171 //==========================================================================================================================================
172 typedef enum
173 {
174  oC_GPIO_Ioctl_Command_TogglePins = oC_Ioctl_MakeCommand(oC_Ioctl_Group_GPIO , 0x01 , NULL ) ,
175  oC_GPIO_Ioctl_Command_SetPinsState = oC_Ioctl_MakeCommand(oC_Ioctl_Group_GPIO , 0x02 , sizeof(oC_GPIO_LLD_PinsState_t*) ) ,
176  oC_GPIO_Ioctl_Command_GetHighPinsState = oC_Ioctl_MakeCommand(oC_Ioctl_Group_GPIO , 0x03 , sizeof(oC_GPIO_LLD_PinsState_t*) ) ,
177  oC_GPIO_Ioctl_Command_GetLowPinsState = oC_Ioctl_MakeCommand(oC_Ioctl_Group_GPIO , 0x04 , sizeof(oC_GPIO_LLD_PinsState_t*) ) ,
179 
180 //==========================================================================================================================================
189 //==========================================================================================================================================
190 typedef struct
191 {
192  oC_Pins_t Pins;
201 
202 //==========================================================================================================================================
211 //==========================================================================================================================================
212 typedef oC_Pins_t * oC_GPIO_Context_t;
213 
214 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
215 
221 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________
222 
223 extern oC_ErrorCode_t oC_GPIO_TurnOn ( void );
224 extern oC_ErrorCode_t oC_GPIO_TurnOff ( void );
225 extern bool oC_GPIO_IsTurnedOn ( void );
226 extern oC_ErrorCode_t oC_GPIO_Configure ( const oC_GPIO_Config_t * Config , oC_GPIO_Context_t * outContext );
227 extern oC_ErrorCode_t oC_GPIO_Unconfigure ( const oC_GPIO_Config_t * Config , oC_GPIO_Context_t * outContext );
228 extern oC_ErrorCode_t oC_GPIO_Ioctl ( oC_GPIO_Context_t Context , oC_Ioctl_Command_t Command , void * Data );
229 extern oC_ErrorCode_t oC_GPIO_QuickOutput ( oC_Pins_t Pins );
230 extern oC_ErrorCode_t oC_GPIO_QuickInput ( oC_Pins_t Pins , oC_GPIO_Pull_t Pull );
231 extern oC_ErrorCode_t oC_GPIO_QuickUnconfigure ( oC_Pins_t Pins );
232 extern oC_ErrorCode_t oC_GPIO_SetSpeed ( oC_Pins_t Pins , oC_GPIO_Speed_t Speed );
233 extern oC_ErrorCode_t oC_GPIO_ReadSpeed ( oC_Pins_t Pins , oC_GPIO_Speed_t * outSpeed );
234 extern oC_ErrorCode_t oC_GPIO_SetCurrent ( oC_Pins_t Pins , oC_GPIO_Current_t Current );
235 extern oC_ErrorCode_t oC_GPIO_ReadCurrent ( oC_Pins_t Pins , oC_GPIO_Current_t * outCurrent );
236 extern oC_ErrorCode_t oC_GPIO_SetMode ( oC_Pins_t Pins , oC_GPIO_Mode_t Mode );
237 extern oC_ErrorCode_t oC_GPIO_ReadMode ( oC_Pins_t Pins , oC_GPIO_Mode_t * outMode );
238 extern oC_ErrorCode_t oC_GPIO_SetPull ( oC_Pins_t Pins , oC_GPIO_Pull_t Pull );
239 extern oC_ErrorCode_t oC_GPIO_ReadPull ( oC_Pins_t Pins , oC_GPIO_Pull_t * outPull );
240 extern oC_ErrorCode_t oC_GPIO_SetOutputCircuit ( oC_Pins_t Pins , oC_GPIO_OutputCircuit_t OutputCircuit );
241 extern oC_ErrorCode_t oC_GPIO_ReadOutputCircuit ( oC_Pins_t Pins , oC_GPIO_OutputCircuit_t * outOutputCircuit );
242 extern oC_ErrorCode_t oC_GPIO_SetInterruptTrigger ( oC_Pins_t Pins , oC_GPIO_IntTrigger_t InterruptTrigger );
243 extern oC_ErrorCode_t oC_GPIO_ReadInterruptTrigger ( oC_Pins_t Pins , oC_GPIO_IntTrigger_t * outInterruptTrigger );
244 extern oC_ErrorCode_t oC_GPIO_FindPinByName ( const char * Name , oC_Pin_t * outPin );
245 extern oC_ErrorCode_t oC_GPIO_WaitForPins ( oC_Pins_t Pins , oC_Time_t Timeout );
246 extern const char * oC_GPIO_GetCurrentNameFromEnum (oC_GPIO_Current_t Current);
247 extern const char * oC_GPIO_GetModeNameFromEnum (oC_GPIO_Mode_t Mode);
248 extern const char * oC_GPIO_GetOutputCircuitNameFromEnum (oC_GPIO_OutputCircuit_t OutputCircuit);
249 extern const char * oC_GPIO_GetPullNameFromEnum (oC_GPIO_Pull_t Pull);
250 extern const char * oC_GPIO_GetSpeedNameFromEnum (oC_GPIO_Speed_t Speed);
251 extern const char * oC_GPIO_GetIntTriggerNameFromEnum (oC_GPIO_IntTrigger_t IntTrigger);
252 
253 /* Redefinitions from the LLD */
254 //==========================================================================================================================================
265 //==========================================================================================================================================
266 extern const char * oC_GPIO_GetPinName( oC_Pin_t Pin );
267 //==========================================================================================================================================
277 //==========================================================================================================================================
278 extern oC_ErrorCode_t oC_GPIO_IsPortCorrect( oC_Port_t Port );
279 //==========================================================================================================================================
289 //==========================================================================================================================================
290 extern oC_ErrorCode_t oC_GPIO_IsPortIndexCorrect( oC_PortIndex_t PortIndex );
291 //==========================================================================================================================================
309 //==========================================================================================================================================
310 extern oC_PinsMask_t oC_GPIO_GetPinsMaskOfPins( oC_Pins_t Pins );
311 //==========================================================================================================================================
321 //==========================================================================================================================================
322 extern oC_Port_t oC_GPIO_GetPortOfPins( oC_Pins_t Pins );
323 //==========================================================================================================================================
333 //==========================================================================================================================================
334 extern oC_PortIndex_t oC_GPIO_PortToPortIndex( oC_Port_t Port );
335 //==========================================================================================================================================
345 //==========================================================================================================================================
346 extern oC_Port_t oC_GPIO_PortIndexToPort( oC_PortIndex_t PortIndex );
347 //==========================================================================================================================================
359 //==========================================================================================================================================
360 extern bool oC_GPIO_IsPinDefined( oC_Pins_t Pin );
361 //==========================================================================================================================================
372 //==========================================================================================================================================
373 extern bool oC_GPIO_ArePinsDefined( oC_Pins_t Pins );
374 //==========================================================================================================================================
384 //==========================================================================================================================================
385 extern bool oC_GPIO_ArePinsCorrect( oC_Pins_t Pins );
386 //==========================================================================================================================================
396 //==========================================================================================================================================
397 extern bool oC_GPIO_IsSinglePin( oC_Pins_t Pins );
398 
399 //==========================================================================================================================================
417 //==========================================================================================================================================
418 extern oC_Pins_t oC_GPIO_GetPinsFor( oC_Port_t Port , oC_PinsMask_t Pins );
419 
420 //==========================================================================================================================================
430 //==========================================================================================================================================
431 extern const char * oC_GPIO_GetPortName( oC_Port_t Port );
432 //==========================================================================================================================================
443 //==========================================================================================================================================
444 extern const char * oC_GPIO_GetPinName( oC_Pins_t Pin );
445 //==========================================================================================================================================
460 //==========================================================================================================================================
461 extern oC_ErrorCode_t oC_GPIO_SetPower( oC_Pins_t Pins , oC_Power_t Power );
462 //==========================================================================================================================================
476 //==========================================================================================================================================
477 extern oC_ErrorCode_t oC_GPIO_ReadPower( oC_Pins_t Pins , oC_Power_t * outPower );
478 
479 //==========================================================================================================================================
492 //==========================================================================================================================================
493 extern oC_ErrorCode_t oC_GPIO_CheckIsPinUsed( oC_Pins_t Pins , bool * outPinUsed );
494 //==========================================================================================================================================
509 //==========================================================================================================================================
510 extern oC_ErrorCode_t oC_GPIO_ArePinsUnused( oC_Pins_t Pins , bool * outPinsUnused );
511 //==========================================================================================================================================
525 //==========================================================================================================================================
526 extern oC_ErrorCode_t oC_GPIO_WriteData( oC_Pins_t Pins , oC_PinsMask_t Data );
527 //==========================================================================================================================================
540 //==========================================================================================================================================
541 extern oC_ErrorCode_t oC_GPIO_ReadData( oC_Pins_t Pins , oC_PinsMask_t * outData );
542 //==========================================================================================================================================
580 //==========================================================================================================================================
581 extern oC_ErrorCode_t oC_GPIO_ReadDataReference( oC_Pins_t Pins , oC_UInt_t ** outDataReference );
582 //==========================================================================================================================================
610 //==========================================================================================================================================
611 extern oC_Pins_t oC_GPIO_GetHighStatePins( oC_Pins_t Pins );
612 //==========================================================================================================================================
642 //==========================================================================================================================================
643 extern oC_Pins_t oC_GPIO_GetLowStatePins( oC_Pins_t Pins );
644 //==========================================================================================================================================
676 //==========================================================================================================================================
677 extern bool oC_GPIO_IsPinsState( oC_Pins_t Pins , oC_GPIO_PinsState_t ExpectedPinsState );
678 //==========================================================================================================================================
698 //==========================================================================================================================================
699 extern void oC_GPIO_SetPinsState( oC_Pins_t Pins , oC_GPIO_PinsState_t PinsState );
700 //==========================================================================================================================================
726 //==========================================================================================================================================
727 extern void oC_GPIO_TogglePinsState( oC_Pins_t Pins );
728 
729 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________
730 
731 
732 #endif /* INC_DRIVERS_GPIO_OC_GPIO_H_ */
reads pins in high state
Definition: oc_gpio.h:176
oC_GPIO_Mode_t
select In/Out mode
Definition: oc_gpio.h:97
Toggles pins state.
Definition: oc_gpio.h:174
oC_GPIO_Protection_t
unlocking special pins
Definition: oc_gpio.h:52
bool oC_GPIO_IsSinglePin(oC_Pins_t Pins)
checks if there is only one pin in pins variable
oC_GPIO_Speed_t Speed
Definition: oc_gpio.h:194
void oC_GPIO_SetPinsState(oC_Pins_t Pins, oC_GPIO_PinsState_t PinsState)
sets pins to the selected state
oC_ErrorCode_t oC_GPIO_SetOutputCircuit(oC_Pins_t Pins, oC_GPIO_OutputCircuit_t OutputCircuit)
configures output circuit
Definition: oc_gpio.c:752
oC_Pins_t Pins
Definition: oc_gpio.h:192
oC_ErrorCode_t oC_GPIO_SetPull(oC_Pins_t Pins, oC_GPIO_Pull_t Pull)
configures pull for pin(s)
Definition: oc_gpio.c:683
oC_GPIO_Pull_t Pull
Definition: oc_gpio.h:197
oC_PortIndex_t oC_GPIO_PortToPortIndex(oC_Port_t Port)
converts port to port index
oC_Pins_t * oC_GPIO_Context_t
The GPIO context structure.
Definition: oc_gpio.h:212
all pins are set to low state
Definition: oc_gpio.h:163
oC_ErrorCode_t oC_GPIO_ReadData(oC_Pins_t Pins, oC_PinsMask_t *outData)
reads data from port
bool oC_GPIO_IsPinsState(oC_Pins_t Pins, oC_GPIO_PinsState_t ExpectedPinsState)
checks if all pins are set to state
bool oC_GPIO_ArePinsCorrect(oC_Pins_t Pins)
checks if pins are correct
oC_ErrorCode_t oC_GPIO_ReadMode(oC_Pins_t Pins, oC_GPIO_Mode_t *outMode)
reads mode configuration
Definition: oc_gpio.c:650
oC_ErrorCode_t oC_GPIO_CheckIsPinUsed(oC_Pins_t Pins, bool *outPinUsed)
checks if the pin is used
oC_Pins_t oC_GPIO_GetPinsFor(oC_Port_t Port, oC_PinsMask_t Pins)
connect port and pins to one variable
oC_ErrorCode_t oC_GPIO_ReadCurrent(oC_Pins_t Pins, oC_GPIO_Current_t *outCurrent)
reads configured current
Definition: oc_gpio.c:582
The file with LLD interface for the GPIO driver.
oC_ErrorCode_t oC_GPIO_WriteData(oC_Pins_t Pins, oC_PinsMask_t Data)
write data in port
GPIO driver configuration structure.
Definition: oc_gpio.h:190
oC_ErrorCode_t oC_GPIO_TurnOn(void)
turns on the module
Definition: oc_gpio.c:108
oC_ErrorCode_t oC_GPIO_ReadPower(oC_Pins_t Pins, oC_Power_t *outPower)
reads power state in a port
bool oC_GPIO_IsTurnedOn(void)
checks if the driver is turned on
Definition: oc_gpio.c:190
oC_GPIO_Current_t Current
Definition: oc_gpio.h:195
oC_ErrorCode_t oC_GPIO_WaitForPins(oC_Pins_t Pins, oC_Time_t Timeout)
waits for interrupt in the pins
Definition: oc_gpio.c:1097
oC_GPIO_PinsState_t
type for storing state of pins
Definition: oc_gpio.h:161
oC_ErrorCode_t oC_GPIO_ArePinsUnused(oC_Pins_t Pins, bool *outPinsUnused)
checks if all of pins are not used
The file with interface for driver creating.
oC_ErrorCode_t oC_GPIO_SetSpeed(oC_Pins_t Pins, oC_GPIO_Speed_t Speed)
configures speed of pin(s)
Definition: oc_gpio.c:474
oC_Pins_t oC_GPIO_GetLowStatePins(oC_Pins_t Pins)
returns pins that are set to low state
oC_ErrorCode_t oC_GPIO_IsPortCorrect(oC_Port_t Port)
checks if the GPIO port is correct
reads pins in low state
Definition: oc_gpio.h:177
oC_ErrorCode_t oC_GPIO_SetInterruptTrigger(oC_Pins_t Pins, oC_GPIO_IntTrigger_t InterruptTrigger)
configures interrupt for pin(s)
Definition: oc_gpio.c:822
oC_GPIO_Speed_t
speed of pins
Definition: oc_gpio.h:66
oC_GPIO_IntTrigger_t
interrupt trigger source
Definition: oc_gpio.h:141
oC_GPIO_Ioctl_Command_t
ioctl commands for GPIO
Definition: oc_gpio.h:172
const char * oC_GPIO_GetPortName(oC_Port_t Port)
returns name of the port
oC_ErrorCode_t oC_GPIO_ReadPull(oC_Pins_t Pins, oC_GPIO_Pull_t *outPull)
reads pull configuration
Definition: oc_gpio.c:718
oC_ErrorCode_t oC_GPIO_Unconfigure(const oC_GPIO_Config_t *Config, oC_GPIO_Context_t *outContext)
Restores default state on pins.
Definition: oc_gpio.c:281
oC_ErrorCode_t oC_GPIO_ReadInterruptTrigger(oC_Pins_t Pins, oC_GPIO_IntTrigger_t *outInterruptTrigger)
reads interrupt trigger
Definition: oc_gpio.c:858
oC_ErrorCode_t oC_GPIO_SetMode(oC_Pins_t Pins, oC_GPIO_Mode_t Mode)
configures mode of pin(s)
Definition: oc_gpio.c:615
bool oC_GPIO_IsPinDefined(oC_Pins_t Pin)
checks if the pin is defined (only one pin)
oC_ErrorCode_t oC_GPIO_SetCurrent(oC_Pins_t Pins, oC_GPIO_Current_t Current)
configures current of pin(s)
Definition: oc_gpio.c:545
oC_GPIO_Mode_t Mode
Definition: oc_gpio.h:196
void oC_GPIO_TogglePinsState(oC_Pins_t Pins)
toggles pins state
oC_GPIO_OutputCircuit_t OutputCircuit
Definition: oc_gpio.h:198
oC_ErrorCode_t oC_GPIO_ReadDataReference(oC_Pins_t Pins, oC_UInt_t **outDataReference)
reads reference to the GPIO data
all pins are set to high state
Definition: oc_gpio.h:164
oC_ErrorCode_t oC_GPIO_TurnOff(void)
Turns off the GPIO driver.
Definition: oc_gpio.c:154
oC_Pins_t oC_GPIO_GetHighStatePins(oC_Pins_t Pins)
returns pins that are set to high state
oC_GPIO_Current_t
output current
Definition: oc_gpio.h:82
oC_GPIO_Protection_t Protection
Definition: oc_gpio.h:193
oC_PinsMask_t oC_GPIO_GetPinsMaskOfPins(oC_Pins_t Pins)
returns pins mask of pins
bool oC_GPIO_ArePinsDefined(oC_Pins_t Pins)
checks if pins are defined
oC_Port_t oC_GPIO_PortIndexToPort(oC_PortIndex_t PortIndex)
converts port index to port
oC_GPIO_OutputCircuit_t
output circuit - open drain/push pull
Definition: oc_gpio.h:126
oC_ErrorCode_t oC_GPIO_Configure(const oC_GPIO_Config_t *Config, oC_GPIO_Context_t *outContext)
configures GPIO pins to work
Definition: oc_gpio.c:207
oC_ErrorCode_t oC_GPIO_FindPinByName(const char *Name, oC_Pin_t *outPin)
searching pin by its name
Definition: oc_gpio.c:1065
const char * oC_GPIO_GetPinName(oC_Pin_t Pin)
returns name of the pin
oC_ErrorCode_t oC_GPIO_ReadSpeed(oC_Pins_t Pins, oC_GPIO_Speed_t *outSpeed)
reads configured speed
Definition: oc_gpio.c:510
oC_ErrorCode_t oC_GPIO_SetPower(oC_Pins_t Pins, oC_Power_t Power)
sets power for a port
oC_GPIO_Pull_t
pull-up/pull-down in input mode
Definition: oc_gpio.h:112
oC_Port_t oC_GPIO_GetPortOfPins(oC_Pins_t Pins)
returns port of pins
oC_ErrorCode_t oC_GPIO_IsPortIndexCorrect(oC_PortIndex_t PortIndex)
checks if the GPIO port index is correct
oC_Power_t
stores registers power state
Definition: oc_stdtypes.h:249
oC_ErrorCode_t oC_GPIO_ReadOutputCircuit(oC_Pins_t Pins, oC_GPIO_OutputCircuit_t *outOutputCircuit)
reads output circuit configuration
Definition: oc_gpio.c:788
#define NULL
pointer to a zero
Definition: oc_null.h:37
oC_GPIO_IntTrigger_t InterruptTrigger
Definition: oc_gpio.h:199