Mini projet LOO

Dependencies:   mbed APDS_9960 mbed-rtos

Dependents:   MoveYourTetris_OK

Home du projet

Committer:
Willheisen
Date:
Wed Apr 20 11:13:53 2016 +0000
Revision:
27:fdcff6af71b5
Parent:
23:298a1314fc81
Child:
28:e932eb039271
test plusieurs matrices

Who changed what in which revision?

UserRevisionLine numberNew 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 27:fdcff6af71b5 67 int cSPI::envoyerMatrice(cMatrice & mat) // Renvoi la reponse SPI
Willheisen 27:fdcff6af71b5 68 {
Willheisen 27:fdcff6af71b5 69 DigitalOut _cs(p14); //avant p8
Willheisen 27:fdcff6af71b5 70 SPI _spi(p11,p12, p13);
Willheisen 27:fdcff6af71b5 71 for(unsigned char nbMat = 0; nbMat < (mat.getLig() % 8); nbMat++) {
Willheisen 9:6f3d8b714a59 72 _cs = 0;
Willheisen 9:6f3d8b714a59 73 wait(0.1);
Willheisen 27:fdcff6af71b5 74 for(unsigned char i = nbMat*8; i < (nbMat*8)+8; i++) {
Willheisen 27:fdcff6af71b5 75 for(unsigned char j = 0; j < mat.getCol(); j ++) {
Willheisen 9:6f3d8b714a59 76 _spi.write(mat.getValTab(i, j));
Willheisen 9:6f3d8b714a59 77 }
Willheisen 9:6f3d8b714a59 78 }
Willheisen 9:6f3d8b714a59 79 wait(0.1);
Willheisen 9:6f3d8b714a59 80 _cs = 1; //avant 0
Willheisen 27:fdcff6af71b5 81 wait(0.01);
Willheisen 27:fdcff6af71b5 82 }
Willheisen 27:fdcff6af71b5 83 return 1; // temporaire
Willheisen 9:6f3d8b714a59 84
Willheisen 9:6f3d8b714a59 85 }