Color sensor reset at the end of calibration added. sensor id auto assignment was changed to be a fixed value assignment to avoid sensor id shift when some sensor is absent.

Dependencies:   UniGraphic mbed vt100

Committer:
Rhyme
Date:
Fri Feb 23 07:51:55 2018 +0000
Revision:
1:8818b793d147
Parent:
0:ce97f6d34336
Wrong behavior when one of color sensor is missing has been fixed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:ce97f6d34336 1 #include "mbed.h"
Rhyme 0:ce97f6d34336 2 #include "vt100.h"
Rhyme 0:ce97f6d34336 3 #include "afSPI.h"
Rhyme 0:ce97f6d34336 4 #include "mbedSPI.h"
Rhyme 0:ce97f6d34336 5
Rhyme 0:ce97f6d34336 6 #if defined (TARGET_KL25Z) || defined (TARGET_TEENSY3_1)
Rhyme 0:ce97f6d34336 7 #ifndef SPI0_C1
Rhyme 0:ce97f6d34336 8 #define SPI0_C1 (*(uint8_t *)0x40076000)
Rhyme 0:ce97f6d34336 9 #endif
Rhyme 0:ce97f6d34336 10 #endif
Rhyme 0:ce97f6d34336 11 /*
Rhyme 0:ce97f6d34336 12 class mbedSPI : public afSPI {
Rhyme 0:ce97f6d34336 13 public:
Rhyme 0:ce97f6d34336 14 mbedSPI(PinName mosi, PinName miso, PinName sckl, PinName cs) ;
Rhyme 0:ce97f6d34336 15 virtual void begin() ;
Rhyme 0:ce97f6d34336 16 virtual void beginSPI() ;
Rhyme 0:ce97f6d34336 17 virtual void endSPI() ;
Rhyme 0:ce97f6d34336 18 virtual void transfer(char *bytes,int len) ;
Rhyme 0:ce97f6d34336 19 private:
Rhyme 0:ce97f6d34336 20 SPI _spi ;
Rhyme 0:ce97f6d34336 21 DigitalOut _cs ;
Rhyme 0:ce97f6d34336 22 } ;
Rhyme 0:ce97f6d34336 23 */
Rhyme 0:ce97f6d34336 24
Rhyme 0:ce97f6d34336 25 mbedSPI::mbedSPI(PinName mosi, PinName miso, PinName sckl, PinName cs) :
Rhyme 0:ce97f6d34336 26 _spi(mosi, miso, sckl), _cs(cs, 1)
Rhyme 0:ce97f6d34336 27 {
Rhyme 0:ce97f6d34336 28 _spi.format(8, 0) ;
Rhyme 0:ce97f6d34336 29 _spi.frequency(1000000) ; /* 1MHz */
Rhyme 0:ce97f6d34336 30
Rhyme 0:ce97f6d34336 31 #if defined (TARGET_KL25Z) || defined (TARGET_TEENSY3_1)
Rhyme 0:ce97f6d34336 32 #ifndef SPI0_C1
Rhyme 0:ce97f6d34336 33 #define SPI0_C1 (*(uint8_t *)0x40076000)
Rhyme 0:ce97f6d34336 34 #endif
Rhyme 0:ce97f6d34336 35 // SPI0_C1 |= 0x01 ; /* LSB First */
Rhyme 0:ce97f6d34336 36 // SPI0_C1 &= 0xFE ; /* MSB First */
Rhyme 0:ce97f6d34336 37 #endif
Rhyme 0:ce97f6d34336 38
Rhyme 0:ce97f6d34336 39 }
Rhyme 0:ce97f6d34336 40
Rhyme 0:ce97f6d34336 41 void mbedSPI::begin(void)
Rhyme 0:ce97f6d34336 42 {
Rhyme 0:ce97f6d34336 43 }
Rhyme 0:ce97f6d34336 44
Rhyme 0:ce97f6d34336 45 void mbedSPI::beginSPI()
Rhyme 0:ce97f6d34336 46 {
Rhyme 0:ce97f6d34336 47 // printf("+") ; fflush(stdout) ;
Rhyme 0:ce97f6d34336 48 _cs = 0 ;
Rhyme 0:ce97f6d34336 49 SPI0_C1 |= 0x01 ; /* LSB First */
Rhyme 0:ce97f6d34336 50 wait_us(1) ;
Rhyme 0:ce97f6d34336 51 }
Rhyme 0:ce97f6d34336 52
Rhyme 0:ce97f6d34336 53 void mbedSPI::endSPI()
Rhyme 0:ce97f6d34336 54 {
Rhyme 0:ce97f6d34336 55 _cs = 1 ;
Rhyme 0:ce97f6d34336 56 SPI0_C1 &= 0xFE ; /* MSB First */
Rhyme 0:ce97f6d34336 57 wait_us(1) ;
Rhyme 0:ce97f6d34336 58 // printf("-") ; fflush(stdout) ;
Rhyme 0:ce97f6d34336 59 }
Rhyme 0:ce97f6d34336 60
Rhyme 0:ce97f6d34336 61 /**
Rhyme 0:ce97f6d34336 62 * on 17-Jan-2018 disable/enable irq added
Rhyme 0:ce97f6d34336 63 * before and after of each _spi.writes
Rhyme 0:ce97f6d34336 64 */
Rhyme 0:ce97f6d34336 65 void mbedSPI::transfer(char *bytes, int len)
Rhyme 0:ce97f6d34336 66 {
Rhyme 0:ce97f6d34336 67 int i ;
Rhyme 0:ce97f6d34336 68 for (i = 0 ; i < len ; i++ ) {
Rhyme 0:ce97f6d34336 69 __disable_irq() ; // Disable Interrupts
Rhyme 0:ce97f6d34336 70 bytes[i] = _spi.write(bytes[i]) ;
Rhyme 0:ce97f6d34336 71 __enable_irq() ; // Enable Interrupts
Rhyme 0:ce97f6d34336 72 }
Rhyme 0:ce97f6d34336 73 }
Rhyme 0:ce97f6d34336 74