Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated documentation for NRF52I2C.h &.cpp and NRF52Pin.h & .cpp #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 39 additions & 22 deletions inc/NRF52I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ class NRF52I2C : public codal::I2C
*/
virtual ~NRF52I2C();

/** Set the frequency of the I2C interface
/**
* Set the frequency of the I2C interface
*
* @param frequency The bus frequency in hertz
* @param frequency The bus frequency in hertz.
*/
virtual int setFrequency(uint32_t frequency);

Expand All @@ -71,26 +72,30 @@ class NRF52I2C : public codal::I2C

/**
* Method to release the given pin from a peripheral, if already bound.
* Device drivers should override this method to disconnect themselves from the give pin
* Device drivers should override this method to disconnect themselves from the given pin
* to allow it to be used by a different peripheral.
*
* @param pin the Pin to be released
* @param pin the Pin to be released.
*/
virtual int releasePin(Pin &pin) override;

/**
* Issues a standard, I2C command write to the I2C bus.
* This consists of:
*
* - Asserting a Start condition on the bus
*
* - Selecting the Slave address (as an 8 bit address)
*
* - Writing a number of raw data bytes provided
*
* - Asserting a Stop condition on the bus
*
* The CPU will busy wait until the transmission is complete.
*
* @param address The 8bit I2C address of the device to write to
* @param data pointer to the bytes to write
* @param len the number of bytes to write
* @param address The 8bit I2C address of the device to write to. This parameter expects the hardware address shifted left once.
* @param data pointer to the bytes to write.
* @param len the number of bytes to write.
* @param repeated Suppresses the generation of a STOP condition if set. Default: false;
*
* @return DEVICE_OK on success, DEVICE_I2C_ERROR if the the write request failed.
Expand All @@ -100,14 +105,18 @@ class NRF52I2C : public codal::I2C
/**
* Issues a standard, 2 byte I2C command read to the I2C bus.
* This consists of:
* - Asserting a Start condition on the bus
* - Selecting the Slave address (as an 8 bit address)
* - reading "len" bytes of raw 8 bit data into the buffer provided
* - Asserting a Stop condition on the bus
*
* - Asserting a Start condition on the bus.
*
* - Selecting the Slave address (as an 8 bit address).
*
* - reading "len" bytes of raw 8 bit data into the buffer provided.
*
* - Asserting a Stop condition on the bus.
*
* The CPU will busy wait until the transmission is complete.
*
* @param address The 8bit I2C address of the device to read from
* @param address The 8bit I2C address of the device to read from. This parameter expects the hardware address shifted left once.
* @param data pointer to store the the bytes read
* @param len the number of bytes to read into the buffer
* @param repeated Suppresses the generation of a STOP condition if set. Default: false;
Expand All @@ -119,18 +128,26 @@ class NRF52I2C : public codal::I2C
/**
* Performs a typical register read operation to the I2C slave device provided.
* This consists of:
* - Asserting a Start condition on the bus
* - Selecting the Slave address (as an 8 bit address, I2C WRITE)
* - Selecting a RAM register address in the slave
* - Asserting a Stop condition on the bus
* - Asserting a Start condition on the bus
* - Selecting the Slave address (as an 8 bit address, I2C READ)
* - Performing an 8 bit read operation (of the requested register)
* - Asserting a Stop condition on the bus
*
* - Asserting a Start condition on the bus.
*
* - Selecting the Slave address (as an 8 bit address, I2C WRITE).
*
* - Selecting a RAM register address in the slave.
*
* - Asserting a Stop condition on the bus.
*
* - Asserting a Start condition on the bus.
*
* - Selecting the Slave address (as an 8 bit address, I2C READ).
*
* - Performing an 8 bit read operation (of the requested register).
*
* - Asserting a Stop condition on the bus.
*
* The CPU will busy wait until the transmission is complete..
* The CPU will busy wait until the transmission is complete.
*
* @param address 8bit I2C address of the device to read from
* @param address 8bit I2C address of the device to read from. This parameter expects the hardware address shifted left once.
* @param reg The 8bit register address of the to read.
* @param data A pointer to a memory location to store the result of the read operation
* @param length The number of mytes to read
Expand Down
26 changes: 25 additions & 1 deletion inc/NRF52Pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ namespace codal
*
* @code
* DevicePin P0(DEVICE_ID_IO_P0, DEVICE_PIN_P0, PIN_CAPABILITY_BOTH);
*
* P0.setDigitalValue(1); // P0 is now HI
* @endcode
*/
Expand All @@ -163,6 +164,7 @@ namespace codal
*
* @code
* DevicePin P0(DEVICE_ID_IO_P0, DEVICE_PIN_P0, PIN_CAPABILITY_BOTH);
*
* P0.getDigitalValue(); // P0 is either 0 or 1;
* @endcode
*/
Expand All @@ -178,6 +180,7 @@ namespace codal
*
* @code
* DevicePin P0(DEVICE_ID_IO_P0, DEVICE_PIN_P0, PIN_CAPABILITY_BOTH);
*
* P0.getDigitalValue(PullUp); // P0 is either 0 or 1;
* @endcode
*/
Expand Down Expand Up @@ -220,6 +223,7 @@ namespace codal
*
* @code
* DevicePin P0(DEVICE_ID_IO_P0, DEVICE_PIN_P0, PIN_CAPABILITY_BOTH);
*
* P0.getAnalogValue(); // P0 is a value in the range of 0 - 1024
* @endcode
*/
Expand Down Expand Up @@ -262,15 +266,21 @@ namespace codal
* @return 1 if pin is touched, 0 if not, or DEVICE_NOT_SUPPORTED if this pin does not support touch capability.
*
* @code
*
* DeviceMessageBus bus;
*
* DevicePin P0(DEVICE_ID_IO_P0, DEVICE_PIN_P0, PIN_CAPABILITY_ALL);
*
* if(P0.isTouched())
*
* {
*
* //do something!
*
* }
*
* // subscribe to events generated by this pin!
*
* bus.listen(DEVICE_ID_IO_P0, DEVICE_BUTTON_EVT_CLICK, someFunction);
* @endcode
*/
Expand All @@ -285,15 +295,21 @@ namespace codal
* @return 1 if pin is touched, 0 if not, or DEVICE_NOT_SUPPORTED if this pin does not support touch capability.
*
* @code
*
* DeviceMessageBus bus;
*
* DevicePin P0(DEVICE_ID_IO_P0, DEVICE_PIN_P0, PIN_CAPABILITY_ALL);
*
* if(P0.isTouched())
*
* {
* //do something!
*
* //do something!
*
* }
*
* // subscribe to events generated by this pin!
*
* bus.listen(DEVICE_ID_IO_P0, DEVICE_BUTTON_EVT_CLICK, someFunction);
* @endcode
*/
Expand Down Expand Up @@ -394,8 +410,11 @@ namespace codal
* Configures the events generated by this DevicePin instance.
*
* DEVICE_PIN_EVENT_ON_EDGE - Configures this pin to a digital input, and generates events whenever a rise/fall is detected on this pin. (DEVICE_PIN_EVT_RISE, DEVICE_PIN_EVT_FALL)
*
* DEVICE_PIN_EVENT_ON_PULSE - Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either HI or LO. (DEVICE_PIN_EVT_PULSE_HI, DEVICE_PIN_EVT_PULSE_LO)
*
* DEVICE_PIN_EVENT_ON_TOUCH - Configures this pin as a makey makey style touch sensor, in the form of a DeviceButton. Normal button events will be generated using the ID of this pin.
*
* DEVICE_PIN_EVENT_NONE - Disables events for this pin.
*
* @param eventType One of: DEVICE_PIN_EVENT_ON_EDGE, DEVICE_PIN_EVENT_ON_PULSE, DEVICE_PIN_EVENT_ON_TOUCH, DEVICE_PIN_EVENT_NONE
Expand All @@ -404,14 +423,19 @@ namespace codal
* DeviceMessageBus bus;
*
* DevicePin P0(DEVICE_ID_IO_P0, DEVICE_PIN_P0, PIN_CAPABILITY_BOTH);
*
* P0.eventOn(DEVICE_PIN_EVENT_ON_PULSE);
*
* void onPulse(Event evt)
*
* {
*
* int duration = evt.timestamp;
*
* }
*
* bus.listen(DEVICE_ID_IO_P0, DEVICE_PIN_EVT_PULSE_HI, onPulse, MESSAGE_BUS_LISTENER_IMMEDIATE)
*
* @endcode
*
* @return DEVICE_OK on success, or DEVICE_INVALID_PARAMETER if the given eventype does not match
Expand Down
81 changes: 48 additions & 33 deletions source/NRF52I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,22 +248,26 @@ int NRF52I2C::waitForStop(int evt)
}

/**
* Issues a standard, I2C command write to the I2C bus.
* This consists of:
* - Asserting a Start condition on the bus
* - Selecting the Slave address (as an 8 bit address)
* - Writing a number of raw data bytes provided
* - Asserting a Stop condition on the bus
*
* The CPU will busy wait until the transmission is complete.
*
* @param address The 8bit I2C address of the device to write to
* @param data pointer to the bytes to write
* @param len the number of bytes to write
* @param repeated Suppresses the generation of a STOP condition if set. Default: false;
*
* @return DEVICE_OK on success, DEVICE_I2C_ERROR if the the write request failed.
*/
* Issues a standard, I2C command write to the I2C bus.
* This consists of:

* - Asserting a Start condition on the bus
*
* - Selecting the Slave address (as an 8 bit address)
*
* - Writing a number of raw data bytes provided
*
* - Asserting a Stop condition on the bus
*
* The CPU will busy wait until the transmission is complete.
*
* @param address The 8bit I2C address of the device to write to. This parameter expects the hardware address shifted left once.
* @param data pointer to the bytes to write.
* @param len the number of bytes to write.
* @param repeated Suppresses the generation of a STOP condition if set. Default: false;
*
* @return DEVICE_OK on success, DEVICE_I2C_ERROR if the the write request failed.
*/
int NRF52I2C::write(uint16_t address, uint8_t *data, int len, bool repeated)
{
address = address >> 1;
Expand Down Expand Up @@ -298,14 +302,18 @@ int NRF52I2C::write(uint16_t address, uint8_t *data, int len, bool repeated)
/**
* Issues a standard, 2 byte I2C command read to the I2C bus.
* This consists of:
* - Asserting a Start condition on the bus
* - Selecting the Slave address (as an 8 bit address)
* - reading "len" bytes of raw 8 bit data into the buffer provided
* - Asserting a Stop condition on the bus
*
* - Asserting a Start condition on the bus.
*
* - Selecting the Slave address (as an 8 bit address).
*
* - reading "len" bytes of raw 8 bit data into the buffer provided.
*
* - Asserting a Stop condition on the bus.
*
* The CPU will busy wait until the transmission is complete.
*
* @param address The 8bit I2C address of the device to read from
* @param address The 8bit I2C address of the device to read from. This parameter expects the hardware address shifted left once.
* @param data pointer to store the the bytes read
* @param len the number of bytes to read into the buffer
* @param repeated Suppresses the generation of a STOP condition if set. Default: false;
Expand Down Expand Up @@ -355,23 +363,30 @@ int NRF52I2C::read(uint16_t address, uint8_t *data, int len, bool repeated)
/**
* Performs a typical register read operation to the I2C slave device provided.
* This consists of:
* - Asserting a Start condition on the bus
* - Selecting the Slave address (as an 8 bit address, I2C WRITE)
* - Selecting a RAM register address in the slave
* - Asserting a Stop condition on the bus
* - Asserting a Start condition on the bus
* - Selecting the Slave address (as an 8 bit address, I2C READ)
* - Performing an 8 bit read operation (of the requested register)
* - Asserting a Stop condition on the bus
*
* - Asserting a Start condition on the bus.
*
* - Selecting the Slave address (as an 8 bit address, I2C WRITE).
*
* - Selecting a RAM register address in the slave.
*
* - Asserting a Stop condition on the bus.
*
* - Asserting a Start condition on the bus.
*
* - Selecting the Slave address (as an 8 bit address, I2C READ).
*
* - Performing an 8 bit read operation (of the requested register).
*
* - Asserting a Stop condition on the bus.
*
* The CPU will busy wait until the transmission is complete..
* The CPU will busy wait until the transmission is complete.
*
* @param address 8bit I2C address of the device to read from
* @param address 8bit I2C address of the device to read from. This parameter expects the hardware address shifted left once.
* @param reg The 8bit register address of the to read.
* @param data A pointer to a memory location to store the result of the read operation
* @param length The number of mytes to read
* @param repeated Use a repeated START/START/STOP transaction if true, or independent
* START/STOP/START/STOP transactions if fasle. Default: true
* @param repeated Use a repeated START/START/STOP transaction if true, or independent START/STOP/START/STOP transactions if fasle. Default: true
*
* @return DEVICE_OK or DEVICE_I2C_ERROR if the the read request failed.
*/
Expand Down
Loading