Explain how you would modify and test your code such that

Post New Homework

Question 2:

You are a firmware engineer for a large project which is developing a new device which is capable of sorting fruit based on its precise colour.

You are responsible for developing the firmware for the front-end sensor. The only hitch is that the hardware is still under development and the electronics team haven't yet chosen the actual sensor that will he used.

However, they have narrowed it down to two different vendors. The electronics team have however told you that the sensor measures illuminance on three different channels, Red, Green, Blue, each with an 8 bit resolution.

A colour is defined by an <R,G,B> tuple. They have also told you that the sensor will probably be interfaced over an SPI bus.

You have been given a pre-existing driver for the SPI bus, which has one relevant command, defined in Kspi..h>:
/* *
* brief Read from the SPI bus
* CT' param address= register address of SPI slave to read from
* @return= value of register
*/
uint8_t spi_read(uint8_t address);

The electronics team tell you that the Red channel is at address Ox01, Green at address 0)02 and Blue at address Ox03 i.e. if you call spi_read(0%.03) the value that will be returned is the intensity of the blue channel. They also tell you that a status register is found at address OxOO which should return 0x97 if the sensor is configured correctly, and this should probably be checked before reading a value from the colour sensor.

(a) Explain, with the aid of code examples where appropriate, how you would go about writing a driver for the colour sensor_ In particular, explain design decisions made in your API,. for example, how you decide to represent the 3-byte colour information.

(b) Discuss, with the aid of code examples where appropriate, how you would go about testing the colour driver without having the actual sensor to hand. Provide some sample tests that could be used to checkthe colour driver, and also higher level code which depends on the colour sensor.

(c) The electronics team tell you that the blue channel is too sensitive and its value should be divided by 2. Explain how you would modify your code and check that it is working correctly.

(d) The electronics team say they have identified a better sensor that they would like to use in the new version of the product. The only issue is that it communicates over an 12C bus, rather than SPI and the order of the Red and Green channels are swapped. You have a similar driver for the 12C bus which has the prototype:

uint82 i2cread(uint8t address);

Explain how you would modify and test your code such that your colour sensor driver would be able to support either the SPI or the I2C sensor, depending on the product version.

Post New Homework
Captcha

Looking tutor’s service for getting help in UK studies or college assignments? Order Now