In the same post, It still some other warning I will like to remove!
Can I ask you some help?
1) conversion from 'int' to 'uint8_t' {aka 'unsigned char'} may change value [-Wconversion]
static uint8_t DV_Rtc_iDayOfWeek(rtc_datetime_t DateTime)
{
DateTime.day = (uint8_t)(DateTime.day += (uint8_t)DateTime.month < 3 ? DateTime.year-- : DateTime.year - 2, 23 * DateTime.month / 9 + DateTime.day + 4 + DateTime.year / 4 - DateTime.year / 100 + DateTime.year / 400) % 7;
return (DateTime.day);
}
Warning is on the lime "DateTime.day = ..."
I get the "formula" directly on wikipedia. I'm not so familiar with this style of "If, elsif.."
2)conversion from 'uint8_t' {aka 'unsigned char'} to 'unsigned char:4' may change value [-Wconversion]
Warnig is on this line
In .h:
typedef struct
{
uint16_t ChannelSelect: 4;
uint16_t BufferMode: 1;
uint16_t RefDetect: 1;
uint16_t RefSelect: 2;
uint16_t GainSelect: 3;
uint16_t Boost: 1;
uint16_t UnipolarBipolar: 1;
uint16_t BurnoutCurrent: 1;
uint16_t VBIAS: 2;
} tCT_AD7795_ConfigurationRegisterBits;
typedef union
{
tCT_AD7795_ConfigurationRegisterBits Bits;
uint16_t Data;
} tCT_AD7795_ConfigurationRegister;
typedef struct
{
uint8_t ChannelSelect;
uint8_t BufferMode;
uint8_t RefDetect;
uint8_t RefSelect;
uint8_t GainSelect;
int16_t NumericalGain;
uint8_t Boost;
uint8_t UnipolarBipolar;
uint8_t BurnoutCurrent;
uint8_t VBIAS;
boolean ErrorGenerateReset;
boolean CheckErrorMoveToFast;
int32_t DefaultValue;
tCT_AD7795_ThermocoupleType ThermoType;
} tCT_AD7795_ChannelCfg;
...
In .c
tCT_AD7795_ConfigurationRegister CT_AD7795_iConfigurationRegister[CT_AD7795_NB_CHANNEL];
tCT_AD7795_ChannelCfg CT_AD7795_ChannelCfg[CT_AD7795_NB_CHANNEL] =
{
/* CT_AD7795_CHANNEL0 : Configured to measure AIN1 */
{
/* ChannelSelect */ CT_AD7795_CONFIG_CHANNEL_AIN1,
/* BufferMode */ CT_AD7795_CONFIG_BUF_ENABLE,
/* RefDetect */ CT_AD7795_CONFIG_REFDET_DISABLE,
/* RefSelect */ CT_AD7795_CONFIG_REFSEL_INTERNAL,
/* GainSelect */ CT_AD7795_CONFIG_GAIN_16, /* If change here, change NumericalGain */
/* NumericalGain */ 16, /* If change here, change GainSelect */
/* Boost */ CT_AD7795_CONFIG_BOOST_ENABLE,
/* UnipolarBipolar */ CT_AD7795_CONFIG_UB_BIPOLAR,
/* BurnoutCurrent */ CT_AD7795_CONFIG_BO_DISABLE,
/* VBIAS */ CT_AD7795_CONFIG_VBIAS_AIN1,
/* ErrorGenerateReset */ TRUE,
/* CheckErrorMoveToFast */ FALSE,
/* DefaultValue */ 0,
/* ThermoType */ CT_AD7795_THEMROCOUPLE_TYPE_K
},
....
void MyFunc(...)
{
CT_AD7795_iConfigurationRegister[ChannelId].Bits.ChannelSelect = CT_AD7795_ChannelCfg[ChannelId].ChannelSelect; /* !!!! Warning on this line */
...}
I understand I try to "cast" byte (8bit) to a bitfield (ie 4 or 2 or 5 bits).
In my opinion, the code run correclty, but it should be great if the warning was controlled and removed.
What can I change to remove it? I have not idea!
Thank