bosko lekovic
/
IO_board_K22
K22 processor
SPIledovi/LedLight.cpp@18:6196688e2a94, 2021-05-16 (annotated)
- Committer:
- bosko001
- Date:
- Sun May 16 22:01:47 2021 +0200
- Revision:
- 18:6196688e2a94
- Parent:
- 12:ea2256d6c725
korigovan PeripheralPins.c u mbedOS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 7:4aa3dac73b66 | 1 | #include "LedLight.h" |
bosko001 | 7:4aa3dac73b66 | 2 | #include "ClassThreadAbstract.h" |
bosko001 | 7:4aa3dac73b66 | 3 | |
bosko001 | 7:4aa3dac73b66 | 4 | #include "mbed.h" |
bosko001 | 12:ea2256d6c725 | 5 | |
bosko001 | 12:ea2256d6c725 | 6 | #include "Pinovi.h" |
bosko001 | 12:ea2256d6c725 | 7 | |
bosko001 | 7:4aa3dac73b66 | 8 | // DigitalOut led(LED1,3); |
bosko001 | 7:4aa3dac73b66 | 9 | |
bosko001 | 7:4aa3dac73b66 | 10 | /************************************** class C_spi ******************************************* */ |
bosko001 | 7:4aa3dac73b66 | 11 | C_spi::C_spi( PinName mosi, PinName miso, PinName sclk, PinName pin_csdata ): SPI( mosi, miso, sclk) //SPI( PTD2, PTD3, PTD1 ) |
bosko001 | 7:4aa3dac73b66 | 12 | { |
bosko001 | 7:4aa3dac73b66 | 13 | p_csdata = new DigitalOut( pin_csdata,1); |
bosko001 | 18:6196688e2a94 | 14 | format( 16, 0); |
bosko001 | 18:6196688e2a94 | 15 | frequency(10000000); |
bosko001 | 7:4aa3dac73b66 | 16 | } |
bosko001 | 7:4aa3dac73b66 | 17 | unsigned short C_spi::transfer( unsigned short tx ) |
bosko001 | 7:4aa3dac73b66 | 18 | { |
bosko001 | 7:4aa3dac73b66 | 19 | // led = 0; |
bosko001 | 7:4aa3dac73b66 | 20 | *p_csdata = 0; |
bosko001 | 7:4aa3dac73b66 | 21 | *p_csdata = 1; |
bosko001 | 7:4aa3dac73b66 | 22 | unsigned short rx = write( tx ); |
bosko001 | 7:4aa3dac73b66 | 23 | *p_csdata = 0; |
bosko001 | 7:4aa3dac73b66 | 24 | *p_csdata = 1; |
bosko001 | 7:4aa3dac73b66 | 25 | // led = 1; |
bosko001 | 7:4aa3dac73b66 | 26 | return rx; |
bosko001 | 7:4aa3dac73b66 | 27 | } |
bosko001 | 7:4aa3dac73b66 | 28 | /********************************************************************************** */ |
bosko001 | 7:4aa3dac73b66 | 29 | |
bosko001 | 7:4aa3dac73b66 | 30 | |
bosko001 | 7:4aa3dac73b66 | 31 | |
bosko001 | 7:4aa3dac73b66 | 32 | /********************************************************************************** */ |
bosko001 | 7:4aa3dac73b66 | 33 | |
bosko001 | 7:4aa3dac73b66 | 34 | |
bosko001 | 12:ea2256d6c725 | 35 | // C_spiled::C_spiled():C_spi( PTD2, PTD3, PTD1, PTC4)//, C_thread() |
bosko001 | 12:ea2256d6c725 | 36 | C_spiled::C_spiled():C_spi( Led_mosi, Led_miso, Led_sclk, Led_cs)//, C_thread() |
bosko001 | 7:4aa3dac73b66 | 37 | { |
bosko001 | 7:4aa3dac73b66 | 38 | |
bosko001 | 7:4aa3dac73b66 | 39 | } |
bosko001 | 7:4aa3dac73b66 | 40 | |
bosko001 | 7:4aa3dac73b66 | 41 | void C_spiled::do_Sifter( void ) |
bosko001 | 7:4aa3dac73b66 | 42 | { |
bosko001 | 7:4aa3dac73b66 | 43 | sifter = u_ledovi.ledovi<<2; |
bosko001 | 7:4aa3dac73b66 | 44 | received = transfer(sifter); |
bosko001 | 7:4aa3dac73b66 | 45 | } |
bosko001 | 7:4aa3dac73b66 | 46 | |
bosko001 | 7:4aa3dac73b66 | 47 | void C_spiled::set_led( char no, E_ledColor ct ) |
bosko001 | 7:4aa3dac73b66 | 48 | { |
bosko001 | 7:4aa3dac73b66 | 49 | switch( no ) |
bosko001 | 7:4aa3dac73b66 | 50 | { |
bosko001 | 7:4aa3dac73b66 | 51 | case 1: u_ledovi.ledpar1 = ct; break; |
bosko001 | 7:4aa3dac73b66 | 52 | case 2: u_ledovi.ledpar2 = ct; break; |
bosko001 | 7:4aa3dac73b66 | 53 | case 3: u_ledovi.ledpar3 = ct; break; |
bosko001 | 7:4aa3dac73b66 | 54 | case 4: u_ledovi.ledpar4 = ct; break; |
bosko001 | 7:4aa3dac73b66 | 55 | case 5: u_ledovi.ledpar5 = ct; break; |
bosko001 | 7:4aa3dac73b66 | 56 | case 6: u_ledovi.ledpar6 = ct; break; |
bosko001 | 7:4aa3dac73b66 | 57 | } |
bosko001 | 7:4aa3dac73b66 | 58 | } |
bosko001 | 7:4aa3dac73b66 | 59 | E_ledColor C_spiled::get_led( char no ) |
bosko001 | 7:4aa3dac73b66 | 60 | { |
bosko001 | 7:4aa3dac73b66 | 61 | E_ledColor ct; |
bosko001 | 7:4aa3dac73b66 | 62 | switch( no ) |
bosko001 | 7:4aa3dac73b66 | 63 | { |
bosko001 | 7:4aa3dac73b66 | 64 | case 1: ct = (E_ledColor)u_ledovi.ledpar1; break; |
bosko001 | 7:4aa3dac73b66 | 65 | case 2: ct = (E_ledColor)u_ledovi.ledpar2; break; |
bosko001 | 7:4aa3dac73b66 | 66 | case 3: ct = (E_ledColor)u_ledovi.ledpar3; break; |
bosko001 | 7:4aa3dac73b66 | 67 | case 4: ct = (E_ledColor)u_ledovi.ledpar4; break; |
bosko001 | 7:4aa3dac73b66 | 68 | case 5: ct = (E_ledColor)u_ledovi.ledpar5; break; |
bosko001 | 7:4aa3dac73b66 | 69 | case 6: ct = (E_ledColor)u_ledovi.ledpar6; break; |
bosko001 | 7:4aa3dac73b66 | 70 | } |
bosko001 | 7:4aa3dac73b66 | 71 | return ct; |
bosko001 | 7:4aa3dac73b66 | 72 | |
bosko001 | 7:4aa3dac73b66 | 73 | } |
bosko001 | 7:4aa3dac73b66 | 74 | |
bosko001 | 7:4aa3dac73b66 | 75 | /********************************************************************************** */ |
bosko001 | 7:4aa3dac73b66 | 76 | |
bosko001 | 7:4aa3dac73b66 | 77 | // refresh beskonacna funkcija se poziva u C_threadu |
bosko001 | 7:4aa3dac73b66 | 78 | |
bosko001 | 7:4aa3dac73b66 | 79 | |
bosko001 | 7:4aa3dac73b66 | 80 | C_ledLight::C_ledLight( ) { } |
bosko001 | 7:4aa3dac73b66 | 81 | C_ledLight::C_ledLight( int stack ):C_thread( stack) { } |
bosko001 | 7:4aa3dac73b66 | 82 | |
bosko001 | 7:4aa3dac73b66 | 83 | void C_ledLight::set_ledLight( char no, E_ledColor c, char t) |
bosko001 | 7:4aa3dac73b66 | 84 | { |
bosko001 | 7:4aa3dac73b66 | 85 | if( no && no<=NO_LED ) {s_ledLight[no-1].ct = c; s_ledLight[no-1].tickPatern= t; } |
bosko001 | 7:4aa3dac73b66 | 86 | } |
bosko001 | 7:4aa3dac73b66 | 87 | |
bosko001 | 7:4aa3dac73b66 | 88 | void C_ledLight::set_ledLight( char no, E_ledColor c ) { if( no && no<=NO_LED ) {s_ledLight[no-1].ct = c;} } |
bosko001 | 7:4aa3dac73b66 | 89 | void C_ledLight::set_ledLightTickPatern( char no, char t ) { if( no && no<=NO_LED ) {s_ledLight[no-1].tickPatern = t;} } |
bosko001 | 7:4aa3dac73b66 | 90 | // void set_ledLight( char no, bool on ) { if( no && no<=NO_LED ) {s_ledLight[no-1].tickPatern = ((on==true) ? 0xff : 0);} } |
bosko001 | 7:4aa3dac73b66 | 91 | void C_ledLight::set_ledLightByte( char Port ) |
bosko001 | 7:4aa3dac73b66 | 92 | { |
bosko001 | 7:4aa3dac73b66 | 93 | for( char i=0, j=1; i<NO_LED; i++, j<<=1 ) { s_ledLight[ i ].tickPatern = ((Port & j) ? 0xff : 0); } |
bosko001 | 7:4aa3dac73b66 | 94 | } |
bosko001 | 7:4aa3dac73b66 | 95 | |
bosko001 | 7:4aa3dac73b66 | 96 | |
bosko001 | 7:4aa3dac73b66 | 97 | S_ledLight C_ledLight::get_ledLight( char no ) { return s_ledLight[no-1];} |
bosko001 | 7:4aa3dac73b66 | 98 | char C_ledLight::get_ledLightTickPatern( char no ) { return s_ledLight[no-1].tickPatern;} |
bosko001 | 7:4aa3dac73b66 | 99 | E_ledColor C_ledLight::get_ledLightColor( char no ) { return s_ledLight[no-1].ct;} |
bosko001 | 7:4aa3dac73b66 | 100 | |
bosko001 | 7:4aa3dac73b66 | 101 | void C_ledLight::apply_ledColorTemplate( const E_ledColor *e_ct ) |
bosko001 | 7:4aa3dac73b66 | 102 | { |
bosko001 | 7:4aa3dac73b66 | 103 | for( int i = 0; i<NO_LED; i++) s_ledLight[i].ct = e_ct[i]; |
bosko001 | 7:4aa3dac73b66 | 104 | } |
bosko001 | 7:4aa3dac73b66 | 105 | |
bosko001 | 7:4aa3dac73b66 | 106 | void C_ledLight::_refresh( void) |
bosko001 | 7:4aa3dac73b66 | 107 | { |
bosko001 | 7:4aa3dac73b66 | 108 | static char j=1; |
bosko001 | 7:4aa3dac73b66 | 109 | |
bosko001 | 18:6196688e2a94 | 110 | set_led( 1, (E_ledColor)( (get_ledLightTickPatern(1) & j) ? ((get_ledLightColor(1))) : 0 ) ); |
bosko001 | 18:6196688e2a94 | 111 | set_led( 2, (E_ledColor)( (get_ledLightTickPatern(2) & j) ? ((get_ledLightColor(2))) : 0 ) ); |
bosko001 | 18:6196688e2a94 | 112 | set_led( 3, (E_ledColor)( (get_ledLightTickPatern(3) & j) ? ((get_ledLightColor(3))) : 0 ) ); |
bosko001 | 18:6196688e2a94 | 113 | set_led( 4, (E_ledColor)( (get_ledLightTickPatern(4) & j) ? ((get_ledLightColor(4))) : 0 ) ); |
bosko001 | 18:6196688e2a94 | 114 | set_led( 5, (E_ledColor)( (get_ledLightTickPatern(5) & j) ? ((get_ledLightColor(5))) : 0 ) ); |
bosko001 | 18:6196688e2a94 | 115 | set_led( 6, (E_ledColor)( (get_ledLightTickPatern(6) & j) ? ((get_ledLightColor(6))) : 0 ) ); |
bosko001 | 7:4aa3dac73b66 | 116 | |
bosko001 | 18:6196688e2a94 | 117 | do_Sifter(); |
bosko001 | 7:4aa3dac73b66 | 118 | |
bosko001 | 7:4aa3dac73b66 | 119 | if( !(j<<=1) ) j = 1; |
bosko001 | 7:4aa3dac73b66 | 120 | |
bosko001 | 7:4aa3dac73b66 | 121 | ThisThread::sleep_for(125ms); |
bosko001 | 7:4aa3dac73b66 | 122 | |
bosko001 | 7:4aa3dac73b66 | 123 | } |
bosko001 | 7:4aa3dac73b66 | 124 | |
bosko001 | 7:4aa3dac73b66 | 125 | // void C_ledLight::refresh( void) |
bosko001 | 7:4aa3dac73b66 | 126 | // { |
bosko001 | 7:4aa3dac73b66 | 127 | |
bosko001 | 7:4aa3dac73b66 | 128 | // // set_ledLight(0, ledRed, 0xff); |
bosko001 | 7:4aa3dac73b66 | 129 | // // set_ledLight(2, ledGreen, 0b01110010); |
bosko001 | 7:4aa3dac73b66 | 130 | |
bosko001 | 7:4aa3dac73b66 | 131 | // // apply_ledColorTemplate(e_colorTemplate); |
bosko001 | 7:4aa3dac73b66 | 132 | // // set_ledLightTickPatern(3, 0xf); |
bosko001 | 7:4aa3dac73b66 | 133 | |
bosko001 | 7:4aa3dac73b66 | 134 | |
bosko001 | 7:4aa3dac73b66 | 135 | // // set_ledLight(3, ledOff); |
bosko001 | 7:4aa3dac73b66 | 136 | |
bosko001 | 7:4aa3dac73b66 | 137 | // //set_ledLightByte(0x1f); |
bosko001 | 7:4aa3dac73b66 | 138 | |
bosko001 | 7:4aa3dac73b66 | 139 | // while(true) |
bosko001 | 7:4aa3dac73b66 | 140 | // { |
bosko001 | 7:4aa3dac73b66 | 141 | |
bosko001 | 7:4aa3dac73b66 | 142 | // _refresh(); |
bosko001 | 7:4aa3dac73b66 | 143 | |
bosko001 | 7:4aa3dac73b66 | 144 | // //printf(" max_stack %d ratio %d\n\r", get_max_stack(), get_stack_ratio()); |
bosko001 | 7:4aa3dac73b66 | 145 | |
bosko001 | 7:4aa3dac73b66 | 146 | // } |
bosko001 | 7:4aa3dac73b66 | 147 | // } |
bosko001 | 7:4aa3dac73b66 | 148 | |
bosko001 | 7:4aa3dac73b66 | 149 | |
bosko001 | 7:4aa3dac73b66 | 150 | |
bosko001 | 7:4aa3dac73b66 | 151 |