int sgm5349_RegWrite(sgm5349Device_t *device, uint8_t channel, uint16_t data, uint8_t update){
HAL_StatusTypeDef status = HAL_OK;
uint32_t regVal = 0;
/* Input Validation Check */
if(device == NULL) return -1;
if(isChannelValid(channel) != 0) return -1;
/* 32bit register value generation with command = 0 or 2 or 3*/
regVal = (channel << 20) | (data << 4);
if(update == 1) regVal |= (3 << 24);
else if(update == 2) regVal |= (2 << 24);
regVal = LittleEndian2BigEndian(regVal);
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,0);
HAL_SPI_Transmit_DMA(device->hspi, (uint8_t *)®Val, 4);
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,1);
if(status != HAL_OK) return (int)status;
return 0;
}
|