From 718fbdab98ae80923a548ac03b7843f5d618a4f6 Mon Sep 17 00:00:00 2001 From: Finlay Davidson Date: Mon, 9 May 2022 17:14:42 +0200 Subject: [PATCH] Replace C-style casts with static_cast --- src/components/ble/DfuService.cpp | 18 ++++++++++-------- src/drivers/DebugPins.cpp | 10 +++++----- src/drivers/SpiNorFlash.cpp | 22 +++++++++++++++------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/components/ble/DfuService.cpp b/src/components/ble/DfuService.cpp index cf99f01f..77dbe2eb 100644 --- a/src/components/ble/DfuService.cpp +++ b/src/components/ble/DfuService.cpp @@ -119,8 +119,10 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) { bootloaderSize = om->om_data[4] + (om->om_data[5] << 8) + (om->om_data[6] << 16) + (om->om_data[7] << 24); applicationSize = om->om_data[8] + (om->om_data[9] << 8) + (om->om_data[10] << 16) + (om->om_data[11] << 24); bleController.FirmwareUpdateTotalBytes(applicationSize); - NRF_LOG_INFO( - "[DFU] -> Start data received : SD size : %d, BT size : %d, app size : %d", softdeviceSize, bootloaderSize, applicationSize); + NRF_LOG_INFO("[DFU] -> Start data received : SD size : %d, BT size : %d, app size : %d", + softdeviceSize, + bootloaderSize, + applicationSize); // wait until SystemTask has finished waking up all devices while (systemTask.IsSleeping()) { @@ -165,10 +167,10 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) { if ((nbPacketReceived % nbPacketsToNotify) == 0 && bytesReceived != applicationSize) { uint8_t data[5] {static_cast(Opcodes::PacketReceiptNotification), - (uint8_t)(bytesReceived & 0x000000FFu), - (uint8_t)(bytesReceived >> 8u), - (uint8_t)(bytesReceived >> 16u), - (uint8_t)(bytesReceived >> 24u)}; + static_cast(bytesReceived & 0x000000FFu), + static_cast(bytesReceived >> 8u), + static_cast(bytesReceived >> 16u), + static_cast(bytesReceived >> 24u)}; NRF_LOG_INFO("[DFU] -> Send packet notification: %d bytes received", bytesReceived); notificationManager.Send(connectionHandle, controlPointCharacteristicHandle, data, 5); } @@ -423,9 +425,9 @@ uint16_t DfuService::DfuImage::ComputeCrc(uint8_t const* p_data, uint32_t size, uint16_t crc = (p_crc == NULL) ? 0xFFFF : *p_crc; for (uint32_t i = 0; i < size; i++) { - crc = (uint8_t)(crc >> 8) | (crc << 8); + crc = static_cast(crc >> 8) | (crc << 8); crc ^= p_data[i]; - crc ^= (uint8_t)(crc & 0xFF) >> 4; + crc ^= static_cast(crc & 0xFF) >> 4; crc ^= (crc << 8) << 4; crc ^= ((crc & 0xFF) << 4) << 1; } diff --git a/src/drivers/DebugPins.cpp b/src/drivers/DebugPins.cpp index 92091280..4b2f0f16 100644 --- a/src/drivers/DebugPins.cpp +++ b/src/drivers/DebugPins.cpp @@ -19,16 +19,16 @@ void debugpins_init() { nrf_gpio_pin_clear(DebugPin4); } void debugpins_set(debugpins_pins pin) { - nrf_gpio_pin_set((uint32_t) (pin)); + nrf_gpio_pin_set(static_cast(pin)); } void debugpins_clear(debugpins_pins pin) { - nrf_gpio_pin_clear((uint32_t) (pin)); + nrf_gpio_pin_clear(static_cast(pin)); } void debugpins_pulse(debugpins_pins pin) { - nrf_gpio_pin_set((uint32_t) (pin)); - nrf_gpio_pin_clear((uint32_t) (pin)); + nrf_gpio_pin_set(static_cast(pin)); + nrf_gpio_pin_clear(static_cast(pin)); } #else void debugpins_init() { @@ -42,4 +42,4 @@ void debugpins_clear(debugpins_pins pin) { void debugpins_pulse(debugpins_pins pin) { } -#endif \ No newline at end of file +#endif diff --git a/src/drivers/SpiNorFlash.cpp b/src/drivers/SpiNorFlash.cpp index ebe3174c..28f82fe6 100644 --- a/src/drivers/SpiNorFlash.cpp +++ b/src/drivers/SpiNorFlash.cpp @@ -11,8 +11,10 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi {spi} { void SpiNorFlash::Init() { device_id = ReadIdentificaion(); - NRF_LOG_INFO( - "[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, device_id.type, device_id.density); + NRF_LOG_INFO("[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", + device_id.manufacturer, + device_id.type, + device_id.density); } void SpiNorFlash::Uninit() { @@ -70,7 +72,10 @@ uint8_t SpiNorFlash::ReadConfigurationRegister() { void SpiNorFlash::Read(uint32_t address, uint8_t* buffer, size_t size) { static constexpr uint8_t cmdSize = 4; - uint8_t cmd[cmdSize] = {static_cast(Commands::Read), (uint8_t) (address >> 16U), (uint8_t) (address >> 8U), (uint8_t) address}; + uint8_t cmd[cmdSize] = {static_cast(Commands::Read), + static_cast(address >> 16U), + static_cast(address >> 8U), + static_cast(address)}; spi.Read(reinterpret_cast(&cmd), cmdSize, buffer, size); } @@ -82,9 +87,9 @@ void SpiNorFlash::WriteEnable() { void SpiNorFlash::SectorErase(uint32_t sectorAddress) { static constexpr uint8_t cmdSize = 4; uint8_t cmd[cmdSize] = {static_cast(Commands::SectorErase), - (uint8_t) (sectorAddress >> 16U), - (uint8_t) (sectorAddress >> 8U), - (uint8_t) sectorAddress}; + static_cast(sectorAddress >> 16U), + static_cast(sectorAddress >> 8U), + static_cast(sectorAddress)}; WriteEnable(); while (!WriteEnabled()) @@ -121,7 +126,10 @@ void SpiNorFlash::Write(uint32_t address, const uint8_t* buffer, size_t size) { uint32_t pageLimit = (addr & ~(pageSize - 1u)) + pageSize; uint32_t toWrite = pageLimit - addr > len ? len : pageLimit - addr; - uint8_t cmd[cmdSize] = {static_cast(Commands::PageProgram), (uint8_t) (addr >> 16U), (uint8_t) (addr >> 8U), (uint8_t) addr}; + uint8_t cmd[cmdSize] = {static_cast(Commands::PageProgram), + static_cast(addr >> 16U), + static_cast(addr >> 8U), + static_cast(addr)}; WriteEnable(); while (!WriteEnabled())