31 #include <oc_stdlib.h> 40 #define _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________ 45 #define DRIVER_NAME LED 46 #define DRIVER_FILE_NAME "led" 47 #define DRIVER_VERSION oC_Driver_MakeVersion(1,0,0) 48 #define REQUIRED_DRIVERS &GPIO,&PWM 49 #define REQUIRED_BOOT_LEVEL oC_Boot_Level_RequireClock | oC_Boot_Level_RequireMemoryManager | oC_Boot_Level_RequireDriversManager 52 #define DRIVER_CONFIGURE oC_LED_Configure 53 #define DRIVER_UNCONFIGURE oC_LED_Unconfigure 54 #define WRITE_TO_DRIVER oC_LED_Write 55 #define HANDLE_IOCTL oC_LED_Ioctl 57 #undef _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________ 67 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 76 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 83 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 89 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 97 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 102 static oC_ErrorCode_t SetLight (
oC_LED_Context_t Context , oC_LED_Index_t LedIndex , uint8_t Light );
104 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 112 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 128 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
131 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress) &&
132 oC_AssignErrorCodeIfFalse(&errorCode , isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM) &&
133 oC_AssignErrorCodeIfFalse(&errorCode , Config->Mode & oC_LED_Mode_RGB , oC_ErrorCode_ModeNotCorrect )
138 if(oC_AssignErrorCodeIfFalse(&errorCode , isram(context) , oC_ErrorCode_AllocationError ))
142 if(oC_AssignErrorCode(&errorCode , ConfigureLeds(context)))
145 *outContext = context;
146 errorCode = oC_ErrorCode_None;
151 if(ksmartfree(context,
sizeof(
struct Context_t),AllocationFlags_CanWaitForever)==
false)
153 errorCode = oC_ErrorCode_ReleaseError;
174 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
177 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress) &&
178 oC_AssignErrorCodeIfFalse(&errorCode , isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM) &&
179 oC_AssignErrorCodeIfFalse(&errorCode , IsContextContext(*outContext) , oC_ErrorCode_ContextNotCorrect )
185 if(ksmartfree(*outContext,
sizeof(
struct Context_t),AllocationFlags_CanWaitForever))
187 if(oC_AssignErrorCode(&errorCode , UnconfigureLeds(context)))
190 errorCode = oC_ErrorCode_None;
195 errorCode = oC_ErrorCode_ReleaseError;
204 oC_ErrorCode_t oC_LED_Write(
oC_LED_Context_t Context ,
const char * Buffer , uint32_t * Size , oC_Time_t Timeout )
206 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
209 oC_AssignErrorCodeIfFalse(&errorCode , IsContextContext(Context) , oC_ErrorCode_ContextNotCorrect ) &&
210 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Buffer) , oC_ErrorCode_WrongAddress ) &&
211 oC_AssignErrorCodeIfFalse(&errorCode , isram(Size) , oC_ErrorCode_OutputAddressNotInRAM) &&
212 oC_AssignErrorCodeIfFalse(&errorCode , (*Size) > 0 , oC_ErrorCode_SizeNotCorrect )
215 char * tempBuffer = ksmartalloc(*Size,&Allocator,AllocationFlags_CanWait1Second);
217 if(oC_AssignErrorCodeIfFalse(&errorCode , isram(tempBuffer) , oC_ErrorCode_AllocationError))
219 unsigned int color = 0;
221 errorCode = sscanf(Buffer,
"%x",&color);
223 oC_AssignErrorCodeIfFalse(&errorCode,ksmartfree(tempBuffer,*Size,AllocationFlags_CanWaitForever),oC_ErrorCode_ReleaseError);
224 oC_AssignErrorCode(&errorCode,oC_LED_SetColor(Context,(oC_Color_t)color));
233 oC_ErrorCode_t oC_LED_Ioctl(
oC_LED_Context_t Context , oC_Ioctl_Command_t Command ,
void * Data )
235 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
238 oC_AssignErrorCodeIfFalse(&errorCode , IsContextContext(Context) , oC_ErrorCode_ContextNotCorrect) &&
239 oC_AssignErrorCodeIfFalse(&errorCode , oC_Ioctl_IsCorrectCommand(Command) , oC_ErrorCode_CommandNotCorrect)
250 errorCode = oC_ErrorCode_CommandNotHandled;
260 oC_ErrorCode_t oC_LED_SetColor(
oC_LED_Context_t Context , oC_Color_t Color )
262 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
264 if(oC_AssignErrorCodeIfFalse(&errorCode , IsContextContext(Context) , oC_ErrorCode_ContextNotCorrect))
266 oC_LED_Mode_t mode = Context->Config.Mode;
268 errorCode = oC_ErrorCode_None;
270 for(oC_LED_Index_t ledIndex = 0 ; ledIndex < oC_LED_Index_NumberOfElements && !oC_ErrorOccur(errorCode); ledIndex++)
274 errorCode = SetLight(Context , ledIndex , (uint8_t)((Color & 0xff0000) >> 16 ) );
285 oC_ErrorCode_t oC_LED_SetLight(
oC_LED_Context_t Context , oC_LED_Index_t LedIndex , uint8_t Light )
287 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
290 oC_AssignErrorCodeIfFalse(&errorCode , IsContextContext(Context) , oC_ErrorCode_ContextNotCorrect) &&
291 oC_AssignErrorCodeIfFalse(&errorCode , LedIndex < oC_LED_Index_NumberOfElements , oC_ErrorCode_IndexNotCorrect)
294 errorCode = SetLight(Context,LedIndex,Light);
300 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 307 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 313 oC_ErrorCode_t errorCode = oC_ErrorCode_None;
314 oC_LED_Mode_t mode = Context->Config.Mode;
317 for(oC_LED_Index_t ledIndex = 0 ; ledIndex < oC_LED_Index_NumberOfElements && !oC_ErrorOccur(errorCode) ; ledIndex++ )
319 oC_Pins_t pin = Context->Config.Pins[ledIndex];
328 .ActiveState = (lowActive) ? oC_PWM_ActiveState_Low : oC_PWM_ActiveState_High ,
329 .MaximumValue = 255 ,
330 .TickFrequency = oC_kHz(26) ,
331 .PermissibleDiffernece = oC_kHz(5)
333 errorCode = oC_PWM_Configure(&pwmConfig,&Context->PwmContexts[ledIndex]);
337 errorCode = oC_GPIO_QuickOutput(pin);
349 oC_ErrorCode_t errorCode = oC_ErrorCode_None;
350 oC_LED_Mode_t mode = Context->Config.Mode;
353 for(oC_LED_Index_t ledIndex = 0 ; ledIndex < oC_LED_Index_NumberOfElements && !oC_ErrorOccur(errorCode) ; ledIndex++ )
355 oC_Pins_t pin = Context->Config.Pins[ledIndex];
364 .ActiveState = (lowActive) ? oC_PWM_ActiveState_Low : oC_PWM_ActiveState_High ,
365 .MaximumValue = 255 ,
366 .TickFrequency = oC_kHz(26) ,
367 .PermissibleDiffernece = oC_kHz(5)
369 errorCode = oC_PWM_Unconfigure(&pwmConfig,&Context->PwmContexts[ledIndex]);
373 errorCode = oC_GPIO_QuickUnconfigure(pin);
390 static oC_ErrorCode_t SetLight(
oC_LED_Context_t Context , oC_LED_Index_t LedIndex , uint8_t Light )
392 oC_ErrorCode_t errorCode = oC_ErrorCode_None;
393 oC_LED_Mode_t mode = Context->Config.Mode;
395 oC_Pins_t pin = Context->Config.Pins[LedIndex];
399 errorCode = oC_PWM_SetValue(Context->PwmContexts[LedIndex],Light);
416 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ static bool oC_Bits_AreBitsSetU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are set
The file with interface for the GPIO driver.
identifier for allocations
The file with interface for the PWM driver.
oC_ErrorCode_t oC_GPIO_WriteData(oC_Pins_t Pins, oC_PinsMask_t Data)
write data in port
PWM driver configuration structure.
The file with interface for driver creating.
The file with interface for the module library.
uint32_t oC_ObjectControl_t
stores object control value
oC_ErrorCode_t oC_LED_Unconfigure(const oC_LED_Config_t *Config, oC_LED_Context_t *outContext)
Restores default state on pins.
LED driver configuration structure.
static oC_ObjectControl_t oC_CountObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId)
counts object control for object
static bool oC_CheckObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId, oC_ObjectControl_t ObjectControl)
checks if object control is correct
oC_ErrorCode_t oC_LED_Configure(const oC_LED_Config_t *Config, oC_LED_Context_t *outContext)
configures LED pins to work
oC_ObjectControl_t ObjectControl
The file with interface for the LED driver.
static bool oC_Bits_IsBitSetU32(uint32_t BitMask, uint8_t BitIndex)
checks if bit is set
The file with interface for string library.
The file with standard input/output operations.
#define NULL
pointer to a zero