Mini projet LOO
Dependencies: mbed APDS_9960 mbed-rtos
Home du projet
src/cSPI.cpp@23:298a1314fc81, 2016-04-15 (annotated)
- Committer:
- clementdoreau
- Date:
- Fri Apr 15 12:13:34 2016 +0000
- Revision:
- 23:298a1314fc81
- Parent:
- 9:6f3d8b714a59
- Child:
- 27:fdcff6af71b5
- Child:
- 35:7aef0bbdf335
Ajout du gesture sensor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Willheisen | 9:6f3d8b714a59 | 1 | /* |
Willheisen | 9:6f3d8b714a59 | 2 | * cSPI.cpp |
Willheisen | 9:6f3d8b714a59 | 3 | * |
Willheisen | 9:6f3d8b714a59 | 4 | * Created on: 5 avr. 2016 |
Willheisen | 9:6f3d8b714a59 | 5 | * Author: clement |
Willheisen | 9:6f3d8b714a59 | 6 | */ |
Willheisen | 9:6f3d8b714a59 | 7 | |
Willheisen | 9:6f3d8b714a59 | 8 | #include "cSPI.h" |
Willheisen | 9:6f3d8b714a59 | 9 | #include "cMatrice.h" |
Willheisen | 9:6f3d8b714a59 | 10 | |
Willheisen | 9:6f3d8b714a59 | 11 | |
Willheisen | 9:6f3d8b714a59 | 12 | |
Willheisen | 9:6f3d8b714a59 | 13 | // CONSTRUCTEURS |
Willheisen | 9:6f3d8b714a59 | 14 | |
Willheisen | 9:6f3d8b714a59 | 15 | cSPI::cSPI(){ |
Willheisen | 9:6f3d8b714a59 | 16 | _freq = 0; |
Willheisen | 9:6f3d8b714a59 | 17 | _mode = 0; |
Willheisen | 9:6f3d8b714a59 | 18 | _bits = 0; |
Willheisen | 9:6f3d8b714a59 | 19 | } |
Willheisen | 9:6f3d8b714a59 | 20 | |
Willheisen | 9:6f3d8b714a59 | 21 | // DESTRUCTEUR |
Willheisen | 9:6f3d8b714a59 | 22 | |
Willheisen | 9:6f3d8b714a59 | 23 | cSPI::~cSPI(){ |
Willheisen | 9:6f3d8b714a59 | 24 | |
Willheisen | 9:6f3d8b714a59 | 25 | } |
Willheisen | 9:6f3d8b714a59 | 26 | // GETTERS |
Willheisen | 9:6f3d8b714a59 | 27 | |
Willheisen | 9:6f3d8b714a59 | 28 | unsigned int cSPI::getFrequence(){ |
Willheisen | 9:6f3d8b714a59 | 29 | return _freq; |
Willheisen | 9:6f3d8b714a59 | 30 | } |
Willheisen | 9:6f3d8b714a59 | 31 | |
Willheisen | 9:6f3d8b714a59 | 32 | unsigned int cSPI::getMode(){ |
Willheisen | 9:6f3d8b714a59 | 33 | return _mode; |
Willheisen | 9:6f3d8b714a59 | 34 | } |
Willheisen | 9:6f3d8b714a59 | 35 | |
Willheisen | 9:6f3d8b714a59 | 36 | unsigned char cSPI::getBits(){ |
Willheisen | 9:6f3d8b714a59 | 37 | return _bits; |
Willheisen | 9:6f3d8b714a59 | 38 | } |
Willheisen | 9:6f3d8b714a59 | 39 | |
Willheisen | 9:6f3d8b714a59 | 40 | // SETTERS |
Willheisen | 9:6f3d8b714a59 | 41 | |
Willheisen | 9:6f3d8b714a59 | 42 | void cSPI::setFrequence(unsigned int freq){ |
Willheisen | 9:6f3d8b714a59 | 43 | _freq = freq; |
Willheisen | 9:6f3d8b714a59 | 44 | } |
Willheisen | 9:6f3d8b714a59 | 45 | |
Willheisen | 9:6f3d8b714a59 | 46 | void cSPI::setMode(unsigned int mode){ |
Willheisen | 9:6f3d8b714a59 | 47 | _mode = mode; |
Willheisen | 9:6f3d8b714a59 | 48 | } |
Willheisen | 9:6f3d8b714a59 | 49 | |
Willheisen | 9:6f3d8b714a59 | 50 | void cSPI::setBits(unsigned char bits){ |
Willheisen | 9:6f3d8b714a59 | 51 | _bits = bits; |
Willheisen | 9:6f3d8b714a59 | 52 | } |
Willheisen | 9:6f3d8b714a59 | 53 | |
Willheisen | 9:6f3d8b714a59 | 54 | // METHODES |
Willheisen | 9:6f3d8b714a59 | 55 | |
Willheisen | 9:6f3d8b714a59 | 56 | void cSPI::initSPI(unsigned int frequence, unsigned int bits, unsigned int mode){ |
Willheisen | 9:6f3d8b714a59 | 57 | DigitalOut _cs(p8); |
Willheisen | 9:6f3d8b714a59 | 58 | SPI _spi(p11,p12, p13); |
Willheisen | 9:6f3d8b714a59 | 59 | _cs = 0; |
clementdoreau | 23:298a1314fc81 | 60 | wait(0.5); |
Willheisen | 9:6f3d8b714a59 | 61 | _spi.frequency(frequence); |
Willheisen | 9:6f3d8b714a59 | 62 | _spi.format(bits, mode); |
clementdoreau | 23:298a1314fc81 | 63 | wait(0.5); |
Willheisen | 9:6f3d8b714a59 | 64 | _cs = 1; |
Willheisen | 9:6f3d8b714a59 | 65 | } |
Willheisen | 9:6f3d8b714a59 | 66 | |
Willheisen | 9:6f3d8b714a59 | 67 | int cSPI::envoyerMatrice(cMatrice & mat){ // Renvoi la reponse SPI |
Willheisen | 9:6f3d8b714a59 | 68 | DigitalOut _cs(p14); //avant p8 |
Willheisen | 9:6f3d8b714a59 | 69 | SPI _spi(p11,p12, p13); |
Willheisen | 9:6f3d8b714a59 | 70 | _cs = 0; |
Willheisen | 9:6f3d8b714a59 | 71 | wait(0.1); |
Willheisen | 9:6f3d8b714a59 | 72 | for(unsigned char i = 0; i < mat.getLig(); i++){ |
Willheisen | 9:6f3d8b714a59 | 73 | for(unsigned char j = 0; j < mat.getCol(); j ++){ |
Willheisen | 9:6f3d8b714a59 | 74 | _spi.write(mat.getValTab(i, j)); |
Willheisen | 9:6f3d8b714a59 | 75 | } |
Willheisen | 9:6f3d8b714a59 | 76 | } |
Willheisen | 9:6f3d8b714a59 | 77 | wait(0.1); |
Willheisen | 9:6f3d8b714a59 | 78 | _cs = 1; //avant 0 |
Willheisen | 9:6f3d8b714a59 | 79 | return 1; // temporaire |
Willheisen | 9:6f3d8b714a59 | 80 | |
Willheisen | 9:6f3d8b714a59 | 81 | } |