Skip to content

Commit c702120

Browse files
authored
Merge pull request #89 from eringerli/cleanup
Cleanup
2 parents 1c1c73e + 4b18d39 commit c702120

5 files changed

+16
-21
lines changed

Adafruit_BusIO_Register.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
2121
uint8_t byteorder,
2222
uint8_t address_width) {
2323
_i2cdevice = i2cdevice;
24-
_spidevice = NULL;
24+
_spidevice = nullptr;
2525
_addrwidth = address_width;
2626
_address = reg_addr;
2727
_byteorder = byteorder;
@@ -50,7 +50,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
5050
uint8_t address_width) {
5151
_spidevice = spidevice;
5252
_spiregtype = type;
53-
_i2cdevice = NULL;
53+
_i2cdevice = nullptr;
5454
_addrwidth = address_width;
5555
_address = reg_addr;
5656
_byteorder = byteorder;
@@ -59,12 +59,12 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
5959

6060
/*!
6161
* @brief Create a register we access over an I2C or SPI Device. This is a
62-
* handy function because we can pass in NULL for the unused interface, allowing
63-
* libraries to mass-define all the registers
64-
* @param i2cdevice The I2CDevice to use for underlying I2C access, if NULL
65-
* we use SPI
66-
* @param spidevice The SPIDevice to use for underlying SPI access, if NULL
67-
* we use I2C
62+
* handy function because we can pass in nullptr for the unused interface,
63+
* allowing libraries to mass-define all the registers
64+
* @param i2cdevice The I2CDevice to use for underlying I2C access, if
65+
* nullptr we use SPI
66+
* @param spidevice The SPIDevice to use for underlying SPI access, if
67+
* nullptr we use I2C
6868
* @param reg_addr The address pointer value for the I2C/SMBus/SPI register,
6969
* can be 8 or 16 bits
7070
* @param type The method we use to read/write data to SPI (which is not

Adafruit_I2CDevice.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
106106
_wire->beginTransmission(_addr);
107107

108108
// Write the prefix data (usually an address)
109-
if ((prefix_len != 0) && (prefix_buffer != NULL)) {
109+
if ((prefix_len != 0) && (prefix_buffer != nullptr)) {
110110
if (_wire->write(prefix_buffer, prefix_len) != prefix_len) {
111111
#ifdef DEBUG_SERIAL
112112
DEBUG_SERIAL.println(F("\tI2CDevice failed to write"));
@@ -128,7 +128,7 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
128128
DEBUG_SERIAL.print(F("\tI2CWRITE @ 0x"));
129129
DEBUG_SERIAL.print(_addr, HEX);
130130
DEBUG_SERIAL.print(F(" :: "));
131-
if ((prefix_len != 0) && (prefix_buffer != NULL)) {
131+
if ((prefix_len != 0) && (prefix_buffer != nullptr)) {
132132
for (uint16_t i = 0; i < prefix_len; i++) {
133133
DEBUG_SERIAL.print(F("0x"));
134134
DEBUG_SERIAL.print(prefix_buffer[i], HEX);

Adafruit_I2CDevice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Adafruit_I2CDevice {
1515

1616
bool read(uint8_t *buffer, size_t len, bool stop = true);
1717
bool write(const uint8_t *buffer, size_t len, bool stop = true,
18-
const uint8_t *prefix_buffer = NULL, size_t prefix_len = 0);
18+
const uint8_t *prefix_buffer = nullptr, size_t prefix_len = 0);
1919
bool write_then_read(const uint8_t *write_buffer, size_t write_len,
2020
uint8_t *read_buffer, size_t read_len,
2121
bool stop = false);

Adafruit_SPIDevice.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,13 @@ Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, int8_t sckpin,
6969
_dataMode = dataMode;
7070
_begun = false;
7171
_spiSetting = new SPISettings(freq, dataOrder, dataMode);
72-
_spi = NULL;
72+
_spi = nullptr;
7373
}
7474

7575
/*!
7676
* @brief Release memory allocated in constructors
7777
*/
78-
Adafruit_SPIDevice::~Adafruit_SPIDevice() {
79-
if (_spiSetting) {
80-
delete _spiSetting;
81-
_spiSetting = nullptr;
82-
}
83-
}
78+
Adafruit_SPIDevice::~Adafruit_SPIDevice() { delete _spiSetting; }
8479

8580
/*!
8681
* @brief Initializes SPI bus and sets CS pin high
@@ -128,7 +123,7 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) {
128123
// hardware SPI is easy
129124

130125
#if defined(SPARK)
131-
_spi->transfer(buffer, buffer, len, NULL);
126+
_spi->transfer(buffer, buffer, len, nullptr);
132127
#elif defined(STM32)
133128
for (size_t i = 0; i < len; i++) {
134129
_spi->transfer(buffer[i]);
@@ -330,7 +325,7 @@ bool Adafruit_SPIDevice::write(const uint8_t *buffer, size_t len,
330325

331326
#ifdef DEBUG_SERIAL
332327
DEBUG_SERIAL.print(F("\tSPIDevice Wrote: "));
333-
if ((prefix_len != 0) && (prefix_buffer != NULL)) {
328+
if ((prefix_len != 0) && (prefix_buffer != nullptr)) {
334329
for (uint16_t i = 0; i < prefix_len; i++) {
335330
DEBUG_SERIAL.print(F("0x"));
336331
DEBUG_SERIAL.print(prefix_buffer[i], HEX);

Adafruit_SPIDevice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Adafruit_SPIDevice {
7878
bool begin(void);
7979
bool read(uint8_t *buffer, size_t len, uint8_t sendvalue = 0xFF);
8080
bool write(const uint8_t *buffer, size_t len,
81-
const uint8_t *prefix_buffer = NULL, size_t prefix_len = 0);
81+
const uint8_t *prefix_buffer = nullptr, size_t prefix_len = 0);
8282
bool write_then_read(const uint8_t *write_buffer, size_t write_len,
8383
uint8_t *read_buffer, size_t read_len,
8484
uint8_t sendvalue = 0xFF);

0 commit comments

Comments
 (0)