/** * ENSICAEN * 6 Boulevard Maréchal Juin * F-14050 Caen Cedex * * This file is owned by ENSICAEN students. No portion of this * document may be reproduced, copied or revised without written * permission of the authors. */ /** * @author Dimitri Boudier * @author * @author * @version 1.0.0 - 2023-09-27 * * @todo Nothing. * @bug None. * @note This driver can be used with only ONE Light click at once. */ /** * @file light_click.c * @brief Driver for the MIKROE "Light click" board * * Ref. https://www.mikroe.com/light-click */ #include "main.h" #include "light_click.h" //! Declared as global in order to be seen by all the driver functions. LIGHT_handle_t light_handle; /***************************************************************************** * FUNCTION DEFINITIONS *****************************************************************************/ void LIGHT_init(SPI_HandleTypeDef *hspi, GPIO_TypeDef *SS_Port, uint16_t SS_Pin) { //! @TODO Attach the SPI peripheral to the Light click handle light_handle.hspi = hspi; //! @TODO Attach the GPIO pin (/Slave Select signal) to the Light click handle light_handle.SS_Port = SS_Port; light_handle.SS_Pin = SS_Pin; } void LIGHT_readBrightnessRaw(uint16_t* brightness_raw) { //! @TODO uint8_t reply[2]; HAL_GPIO_WritePin(light_handle.SS_Port, light_handle.SS_Pin, RESET); HAL_SPI_Receive(light_handle.hspi, reply, 2, HAL_MAX_DELAY); HAL_GPIO_WritePin(light_handle.SS_Port, light_handle.SS_Pin, SET); *brightness_raw = (uint16_t)(reply[0] & 0x1F) << 7; *brightness_raw += (uint16_t)(reply[1] ) >> 1; } void LIGHT_readBrightnessPercentage(float* brightness_percentage) { //! @TODO uint16_t brightness_raw; LIGHT_readBrightnessRaw( &brightness_raw ); *brightness_percentage = (float)brightness_raw; *brightness_percentage /= 4096.0; *brightness_percentage *= 100.0; }