K22 processor

Committer:
bosko001
Date:
Sun Mar 21 18:20:15 2021 +0100
Revision:
7:4aa3dac73b66
Child:
12:ea2256d6c725
novi pocetak

Who changed what in which revision?

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