LCM — CH32V003 Light Control Module
Light Control Module, I2C slave
Loading...
Searching...
No Matches
lcm_module.h File Reference
#include <stdint.h>
#include "user_data.h"

Go to the source code of this file.

Macros

#define LCM_I2C_ADDR_FACTORY   0x7FU /* заводской адрес (7 бит) */
 
#define LCM_I2C_SPEED_HZ   100000U /* Standard-mode I2C */
 
#define LCM_ID   0x01U /* ID модуля контроллера освещения (LCM) */
 
#define LCM_RELAY_COUNT   8U
 
#define LCM_GROUP_COUNT   4U
 
#define LCM_NVM_OFF_MAGIC   0U
 
#define LCM_NVM_OFF_I2C_ADDR   1U
 
#define LCM_NVM_OFF_GROUP_BASE   2U
 
#define LCM_NVM_SIZE   6U
 
#define LCM_NVM_MAGIC   0x4CU /* ASCII 'L' — признак валидной NVM */
 
#define LCM_LAMP_0_ON   0x00U
 
#define LCM_LAMP_1_ON   0x01U
 
#define LCM_LAMP_2_ON   0x02U
 
#define LCM_LAMP_3_ON   0x03U
 
#define LCM_LAMP_4_ON   0x04U
 
#define LCM_LAMP_5_ON   0x05U
 
#define LCM_LAMP_6_ON   0x06U
 
#define LCM_LAMP_7_ON   0x07U
 
#define LCM_LAMP_0_OFF   0x08U
 
#define LCM_LAMP_1_OFF   0x09U
 
#define LCM_LAMP_2_OFF   0x0AU
 
#define LCM_LAMP_3_OFF   0x0BU
 
#define LCM_LAMP_4_OFF   0x0CU
 
#define LCM_LAMP_5_OFF   0x0DU
 
#define LCM_LAMP_6_OFF   0x0EU
 
#define LCM_LAMP_7_OFF   0x0FU
 
#define LCM_LAMP_ALL_ON   0x10U /* все 8 реле вкл */
 
#define LCM_LAMP_ALL_OFF   0x11U /* все 8 реле выкл */
 
#define LCM_GROUP_0_ON   0x12U
 
#define LCM_GROUP_1_ON   0x13U
 
#define LCM_GROUP_2_ON   0x14U
 
#define LCM_GROUP_3_ON   0x15U
 
#define LCM_GROUP_0_OFF   0x16U
 
#define LCM_GROUP_1_OFF   0x17U
 
#define LCM_GROUP_2_OFF   0x18U
 
#define LCM_GROUP_3_OFF   0x19U
 
#define LCM_RESET   0x1AU /* сброс: адрес 0x7F, группы 0, reboot */
 
#define LCM_GET_ERROR   0x1CU /* код последней ошибки */
 
#define LCM_GET_ID   0x1DU /* ID модуля */
 
#define LCM_LAMP_ON   0x20U /* param: маска включаемых реле */
 
#define LCM_LAMP_OFF   0x21U /* param: маска выключаемых реле */
 
#define LCM_GROUP_ON   0x22U /* param: маска включаемых групп */
 
#define LCM_GROUP_OFF   0x23U /* param: маска выключаемых групп */
 
#define LCM_GROUP_0_SET   0x24U /* param: состав группы 0 → NVM */
 
#define LCM_GROUP_1_SET   0x25U
 
#define LCM_GROUP_2_SET   0x26U
 
#define LCM_GROUP_3_SET   0x27U
 
#define LCM_SET_ADDR   0x28U /* param: новый 7-битный I2C-адрес */
 
#define LCM_ERR_NONE   0x00U /* ошибок нет */
 
#define LCM_ERR_UNKNOWN_CMD   0x01U /* неизвестная команда (резерв) */
 
#define LCM_ERR_BAD_PARAM   0x02U /* некорректный параметр (напр. addr > 0x7F) */
 
#define LCM_ERR_I2C_BERR   0x03U /* Bus error: нарушение протокола */
 
#define LCM_ERR_I2C_OVR   0x04U /* Overrun: не успели обработать DATAR */
 
#define LCM_ERR_I2C_ARLO   0x05U /* Arbitration lost */
 
#define LCM_ERR_USER_DATA_COMMIT   0x06U /* сбой записи user_data в flash */
 
#define LCM_ERR_USER_DATA_PARAM   0x07U /* NULL-указатель или некорректный параметр */
 
#define LCM_ERR_USER_DATA_RANGE   0x08U /* offset/len выходят за USER_DATA_CAPACITY */
 
#define LCM_ERR_USER_DATA_FLASH   0x09U /* ошибка программирования/стирания flash */
 
#define LCM_ERR_USER_DATA_BUSY   0x0AU /* flash занят (редко, при вложенных вызовах) */
 
#define LCM_ERR_GPIO_INIT   0x0BU /* сбой инициализации GPIO */
 
#define LCM_ERR_GPIO_SET   0x0CU /* сбой установки GPIO */
 
#define LCM_ERR_GPIO_GET   0x0DU /* сбой чтения уровня GPIO (readback) */
 
#define LCM_ERR_GPIO_CLEAR   0x0EU /* сбой очистки GPIO */
 
#define LCM_ERR_GPIO_SET_ALL   0x0FU /* сбой установки всех GPIO */
 
#define LCM_ERR_GPIO_CLEAR_ALL   0x10U /* сбой очистки всех GPIO */
 

Functions

void LCM_Module_ExecuteSingleByte (uint8_t cmd)
 
void LCM_Module_ExecuteTwoByte (uint8_t cmd, uint8_t param)
 
void LCM_Module_SetError (uint8_t err)
 
void LCM_Module_ReportUserDataStatus (UserData_Status st)
 
uint8_t LCM_Module_GetI2cAddr (void)
 
uint8_t LCM_Module_GetRelayState (void)
 
const uint8_t * LCM_Module_GetGroupMasks (void)
 
void LCM_Module_Init (void)
 
void LCM_Module_Poll (void)
 

Macro Definition Documentation

◆ LCM_ERR_BAD_PARAM

#define LCM_ERR_BAD_PARAM   0x02U /* некорректный параметр (напр. addr > 0x7F) */

Definition at line 176 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_Module_ExecuteTwoByte().

◆ LCM_ERR_GPIO_CLEAR

#define LCM_ERR_GPIO_CLEAR   0x0EU /* сбой очистки GPIO */

Definition at line 194 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_Relay_Apply().

◆ LCM_ERR_GPIO_CLEAR_ALL

#define LCM_ERR_GPIO_CLEAR_ALL   0x10U /* сбой очистки всех GPIO */

Definition at line 196 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_Relay_Apply().

◆ LCM_ERR_GPIO_GET

#define LCM_ERR_GPIO_GET   0x0DU /* сбой чтения уровня GPIO (readback) */

Definition at line 193 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), LCM_Relay_Apply(), and LCM_Relay_Init().

◆ LCM_ERR_GPIO_INIT

#define LCM_ERR_GPIO_INIT   0x0BU /* сбой инициализации GPIO */

Definition at line 191 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_Relay_Init().

◆ LCM_ERR_GPIO_SET

#define LCM_ERR_GPIO_SET   0x0CU /* сбой установки GPIO */

Definition at line 192 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_Relay_Apply().

◆ LCM_ERR_GPIO_SET_ALL

#define LCM_ERR_GPIO_SET_ALL   0x0FU /* сбой установки всех GPIO */

Definition at line 195 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_Relay_Apply().

◆ LCM_ERR_I2C_ARLO

#define LCM_ERR_I2C_ARLO   0x05U /* Arbitration lost */

Definition at line 181 of file lcm_module.h.

Referenced by EventLog_LcmErrName().

◆ LCM_ERR_I2C_BERR

#define LCM_ERR_I2C_BERR   0x03U /* Bus error: нарушение протокола */

Definition at line 179 of file lcm_module.h.

Referenced by EventLog_LcmErrName().

◆ LCM_ERR_I2C_OVR

#define LCM_ERR_I2C_OVR   0x04U /* Overrun: не успели обработать DATAR */

Definition at line 180 of file lcm_module.h.

Referenced by EventLog_LcmErrName().

◆ LCM_ERR_NONE

#define LCM_ERR_NONE   0x00U /* ошибок нет */

◆ LCM_ERR_UNKNOWN_CMD

#define LCM_ERR_UNKNOWN_CMD   0x01U /* неизвестная команда (резерв) */

Definition at line 175 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_Module_ExecuteSingleByte().

◆ LCM_ERR_USER_DATA_BUSY

#define LCM_ERR_USER_DATA_BUSY   0x0AU /* flash занят (редко, при вложенных вызовах) */

Definition at line 188 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_UserDataErrorCode().

◆ LCM_ERR_USER_DATA_COMMIT

#define LCM_ERR_USER_DATA_COMMIT   0x06U /* сбой записи user_data в flash */

Definition at line 184 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_SetUserDataCommitError().

◆ LCM_ERR_USER_DATA_FLASH

#define LCM_ERR_USER_DATA_FLASH   0x09U /* ошибка программирования/стирания flash */

Definition at line 187 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_UserDataErrorCode().

◆ LCM_ERR_USER_DATA_PARAM

#define LCM_ERR_USER_DATA_PARAM   0x07U /* NULL-указатель или некорректный параметр */

Definition at line 185 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_UserDataErrorCode().

◆ LCM_ERR_USER_DATA_RANGE

#define LCM_ERR_USER_DATA_RANGE   0x08U /* offset/len выходят за USER_DATA_CAPACITY */

Definition at line 186 of file lcm_module.h.

Referenced by EventLog_LcmErrName(), and LCM_UserDataErrorCode().

◆ LCM_GET_ERROR

#define LCM_GET_ERROR   0x1CU /* код последней ошибки */

Definition at line 143 of file lcm_module.h.

Referenced by LCM_IsReadCmd(), and LCM_Module_ExecuteSingleByte().

◆ LCM_GET_ID

#define LCM_GET_ID   0x1DU /* ID модуля */

Definition at line 144 of file lcm_module.h.

Referenced by LCM_IsReadCmd(), and LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_0_OFF

#define LCM_GROUP_0_OFF   0x16U

Definition at line 133 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_0_ON

#define LCM_GROUP_0_ON   0x12U

Definition at line 127 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_0_SET

#define LCM_GROUP_0_SET   0x24U /* param: состав группы 0 → NVM */

Definition at line 161 of file lcm_module.h.

Referenced by LCM_Module_ExecuteTwoByte().

◆ LCM_GROUP_1_OFF

#define LCM_GROUP_1_OFF   0x17U

Definition at line 134 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_1_ON

#define LCM_GROUP_1_ON   0x13U

Definition at line 128 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_1_SET

#define LCM_GROUP_1_SET   0x25U

Definition at line 162 of file lcm_module.h.

Referenced by LCM_Module_ExecuteTwoByte().

◆ LCM_GROUP_2_OFF

#define LCM_GROUP_2_OFF   0x18U

Definition at line 135 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_2_ON

#define LCM_GROUP_2_ON   0x14U

Definition at line 129 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_2_SET

#define LCM_GROUP_2_SET   0x26U

Definition at line 163 of file lcm_module.h.

Referenced by LCM_Module_ExecuteTwoByte().

◆ LCM_GROUP_3_OFF

#define LCM_GROUP_3_OFF   0x19U

Definition at line 136 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_3_ON

#define LCM_GROUP_3_ON   0x15U

Definition at line 130 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_GROUP_3_SET

#define LCM_GROUP_3_SET   0x27U

Definition at line 164 of file lcm_module.h.

Referenced by LCM_Module_ExecuteTwoByte().

◆ LCM_GROUP_COUNT

#define LCM_GROUP_COUNT   4U

◆ LCM_GROUP_OFF

#define LCM_GROUP_OFF   0x23U /* param: маска выключаемых групп */

Definition at line 159 of file lcm_module.h.

Referenced by LCM_Module_ExecuteTwoByte().

◆ LCM_GROUP_ON

#define LCM_GROUP_ON   0x22U /* param: маска включаемых групп */

Definition at line 158 of file lcm_module.h.

Referenced by LCM_Module_ExecuteTwoByte().

◆ LCM_I2C_ADDR_FACTORY

#define LCM_I2C_ADDR_FACTORY   0x7FU /* заводской адрес (7 бит) */

◆ LCM_I2C_SPEED_HZ

#define LCM_I2C_SPEED_HZ   100000U /* Standard-mode I2C */

Definition at line 58 of file lcm_module.h.

Referenced by LCM_I2C_Init().

◆ LCM_ID

#define LCM_ID   0x01U /* ID модуля контроллера освещения (LCM) */

Definition at line 65 of file lcm_module.h.

Referenced by EventLog_BootBanner(), and LCM_Module_ExecuteSingleByte().

◆ LCM_LAMP_0_OFF

#define LCM_LAMP_0_OFF   0x08U

Definition at line 114 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_LAMP_0_ON

#define LCM_LAMP_0_ON   0x00U

Definition at line 104 of file lcm_module.h.

◆ LCM_LAMP_1_OFF

#define LCM_LAMP_1_OFF   0x09U

Definition at line 115 of file lcm_module.h.

◆ LCM_LAMP_1_ON

#define LCM_LAMP_1_ON   0x01U

Definition at line 105 of file lcm_module.h.

◆ LCM_LAMP_2_OFF

#define LCM_LAMP_2_OFF   0x0AU

Definition at line 116 of file lcm_module.h.

◆ LCM_LAMP_2_ON

#define LCM_LAMP_2_ON   0x02U

Definition at line 106 of file lcm_module.h.

◆ LCM_LAMP_3_OFF

#define LCM_LAMP_3_OFF   0x0BU

Definition at line 117 of file lcm_module.h.

◆ LCM_LAMP_3_ON

#define LCM_LAMP_3_ON   0x03U

Definition at line 107 of file lcm_module.h.

◆ LCM_LAMP_4_OFF

#define LCM_LAMP_4_OFF   0x0CU

Definition at line 118 of file lcm_module.h.

◆ LCM_LAMP_4_ON

#define LCM_LAMP_4_ON   0x04U

Definition at line 108 of file lcm_module.h.

◆ LCM_LAMP_5_OFF

#define LCM_LAMP_5_OFF   0x0DU

Definition at line 119 of file lcm_module.h.

◆ LCM_LAMP_5_ON

#define LCM_LAMP_5_ON   0x05U

Definition at line 109 of file lcm_module.h.

◆ LCM_LAMP_6_OFF

#define LCM_LAMP_6_OFF   0x0EU

Definition at line 120 of file lcm_module.h.

◆ LCM_LAMP_6_ON

#define LCM_LAMP_6_ON   0x06U

Definition at line 110 of file lcm_module.h.

◆ LCM_LAMP_7_OFF

#define LCM_LAMP_7_OFF   0x0FU

Definition at line 121 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_LAMP_7_ON

#define LCM_LAMP_7_ON   0x07U

Definition at line 111 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_LAMP_ALL_OFF

#define LCM_LAMP_ALL_OFF   0x11U /* все 8 реле выкл */

Definition at line 124 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_LAMP_ALL_ON

#define LCM_LAMP_ALL_ON   0x10U /* все 8 реле вкл */

Definition at line 123 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_LAMP_OFF

#define LCM_LAMP_OFF   0x21U /* param: маска выключаемых реле */

Definition at line 157 of file lcm_module.h.

Referenced by LCM_Module_ExecuteTwoByte().

◆ LCM_LAMP_ON

#define LCM_LAMP_ON   0x20U /* param: маска включаемых реле */

Definition at line 156 of file lcm_module.h.

Referenced by LCM_IsTwoByteCmd(), and LCM_Module_ExecuteTwoByte().

◆ LCM_NVM_MAGIC

#define LCM_NVM_MAGIC   0x4CU /* ASCII 'L' — признак валидной NVM */

Definition at line 90 of file lcm_module.h.

Referenced by LCM_LoadConfig(), LCM_Module_Poll(), and LCM_NvmWriteConfig().

◆ LCM_NVM_OFF_GROUP_BASE

#define LCM_NVM_OFF_GROUP_BASE   2U

Definition at line 88 of file lcm_module.h.

Referenced by LCM_LoadConfig(), LCM_Module_Poll(), and LCM_NvmWriteConfig().

◆ LCM_NVM_OFF_I2C_ADDR

#define LCM_NVM_OFF_I2C_ADDR   1U

Definition at line 87 of file lcm_module.h.

Referenced by LCM_LoadConfig(), LCM_Module_Poll(), and LCM_NvmWriteConfig().

◆ LCM_NVM_OFF_MAGIC

#define LCM_NVM_OFF_MAGIC   0U

Definition at line 86 of file lcm_module.h.

Referenced by LCM_LoadConfig(), LCM_Module_Poll(), and LCM_NvmWriteConfig().

◆ LCM_NVM_SIZE

#define LCM_NVM_SIZE   6U

Definition at line 89 of file lcm_module.h.

Referenced by LCM_Module_Poll(), and LCM_NvmWriteConfig().

◆ LCM_RELAY_COUNT

#define LCM_RELAY_COUNT   8U

Definition at line 66 of file lcm_module.h.

Referenced by LCM_Relay_Apply(), and LCM_Relay_Init().

◆ LCM_RESET

#define LCM_RESET   0x1AU /* сброс: адрес 0x7F, группы 0, reboot */

Definition at line 138 of file lcm_module.h.

Referenced by LCM_Module_ExecuteSingleByte().

◆ LCM_SET_ADDR

#define LCM_SET_ADDR   0x28U /* param: новый 7-битный I2C-адрес */

Definition at line 166 of file lcm_module.h.

Referenced by LCM_IsTwoByteCmd(), and LCM_Module_ExecuteTwoByte().

Function Documentation

◆ LCM_Module_ExecuteSingleByte()

◆ LCM_Module_ExecuteTwoByte()

◆ LCM_Module_GetGroupMasks()

const uint8_t * LCM_Module_GetGroupMasks ( void )

Definition at line 469 of file lcm_module.c.

References s_group_mask.

Referenced by main().

◆ LCM_Module_GetI2cAddr()

uint8_t LCM_Module_GetI2cAddr ( void )

Definition at line 459 of file lcm_module.c.

References s_i2c_addr.

Referenced by main().

◆ LCM_Module_GetRelayState()

uint8_t LCM_Module_GetRelayState ( void )

Definition at line 464 of file lcm_module.c.

References s_relay_state.

Referenced by main().

◆ LCM_Module_Init()

◆ LCM_Module_Poll()

◆ LCM_Module_ReportUserDataStatus()

void LCM_Module_ReportUserDataStatus ( UserData_Status st)

Definition at line 452 of file lcm_module.c.

References LCM_SetUserDataError(), and USER_DATA_OK.

Referenced by main().

◆ LCM_Module_SetError()

void LCM_Module_SetError ( uint8_t err)

Definition at line 64 of file lcm_module.c.

References LCM_SetError().