Mini projet LOO
Dependencies: mbed APDS_9960 mbed-rtos
Home du projet
src/cSPI.cpp
- Committer:
- clementdoreau
- Date:
- 2016-04-20
- Revision:
- 29:95469b25e187
- Parent:
- 28:e932eb039271
- Child:
- 30:c647da947bd9
File content as of revision 29:95469b25e187:
/* * cSPI.cpp * * Created on: 5 avr. 2016 * Author: clement */ #include "cSPI.h" #include "cMatrice.h" DigitalOut _cs(p14); SPI _spi(p11,p12, p13); // CONSTRUCTEURS cSPI::cSPI() { _freq = 0; _mode = 0; _bits = 0; } cSPI::cSPI(unsigned int f, unsigned int m, unsigned int b) { _freq = f; _mode = m; _bits = b; _cs = 0; wait(0.5); _spi.frequency(_freq); _spi.format(_bits, _mode); wait(0.5); _cs = 1; } // DESTRUCTEUR cSPI::~cSPI() { } // GETTERS unsigned int cSPI::getFrequence() { return _freq; } unsigned int cSPI::getMode() { return _mode; } unsigned int cSPI::getBits() { return _bits; } // SETTERS void cSPI::setFrequence(unsigned int freq) { _freq = freq; } void cSPI::setMode(unsigned int mode) { _mode = mode; } void cSPI::setBits(unsigned int bits) { _bits = bits; } // METHODES void cSPI::initSPI(unsigned int frequence, unsigned int bits, unsigned int mode) { _cs = 0; wait(0.5); _spi.frequency(frequence); _spi.format(bits, mode); wait(0.5); _cs = 1; } int cSPI::envoyerMatrice(cMatrice & mat) // Renvoi la reponse SPI { int i = 0; _cs = 0; wait(0.5); for(; i < mat.getLig()/2; i++) { for(int j = 0; j < mat.getCol(); j ++) { _spi.write(mat.getValTab(i, j)); } } wait(0.01); for(; i < mat.getLig(); i++) { for(int j = 0; j < mat.getCol(); j ++) { _spi.write(mat.getValTab(i, j)); } } wait(0.5); _cs = 1; //avant 0 return 1; // temporaire } void cSPI::configurerNbMatrices(const int nb) { _cs = 0; wait(0.5); _spi.write(0x25); _spi.write(nb); wait(0.5); _cs = 1; }