Eli Hughes / Mbed 2 deprecated CHEM_CONTROL

Dependencies:   mbed MODSERIAL

Dependents:   screentest

Committer:
emh203
Date:
Thu Aug 06 15:02:29 2015 +0000
Revision:
1:d64ac853223c
Parent:
0:7798270c1f52
Child:
2:73a028278c5c
Updated the 4 to 20mA to use a sense resistor of 82 ohms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emh203 0:7798270c1f52 1 #include "mbed.h"
emh203 0:7798270c1f52 2 #include "CHEM_BOX_INTERFACE.h"
emh203 0:7798270c1f52 3 #include "MODSERIAL.h"
emh203 0:7798270c1f52 4 #include <stdio.h>
emh203 0:7798270c1f52 5 #include <stdarg.h>
emh203 0:7798270c1f52 6
emh203 0:7798270c1f52 7 //Mbed Objects
emh203 0:7798270c1f52 8
emh203 0:7798270c1f52 9 DigitalOut AIO_ADC1_CS(p30);
emh203 0:7798270c1f52 10
emh203 0:7798270c1f52 11 DigitalOut AIO_ADC2_CS(p29);
emh203 0:7798270c1f52 12
emh203 0:7798270c1f52 13 PwmOut BUZZER_CONTROL(p26);
emh203 0:7798270c1f52 14
emh203 0:7798270c1f52 15 DigitalOut MCU_SR_CLEAR(p25);
emh203 0:7798270c1f52 16
emh203 0:7798270c1f52 17 DigitalOut AIO_DAC1_CS(p24);
emh203 0:7798270c1f52 18
emh203 0:7798270c1f52 19 DigitalOut AIO_DAC2_CS(p23);
emh203 0:7798270c1f52 20
emh203 0:7798270c1f52 21 DigitalOut MFC_POWER_CONTROL(p22);
emh203 0:7798270c1f52 22
emh203 0:7798270c1f52 23 PwmOut FAN_CONTROL(p21);
emh203 0:7798270c1f52 24
emh203 0:7798270c1f52 25 SPI SPI1(p5,p6,p7);
emh203 0:7798270c1f52 26
emh203 0:7798270c1f52 27 DigitalOut MCU_SR_LOAD(p8);
emh203 0:7798270c1f52 28
emh203 0:7798270c1f52 29 SPI SPI0(p11,p12,p13);
emh203 0:7798270c1f52 30
emh203 0:7798270c1f52 31 DigitalOut SmartSwitch_SS(p14);
emh203 0:7798270c1f52 32
emh203 0:7798270c1f52 33 BusOut TEMP_SENSE_ADDRESS(p15,p16,p17,p18);
emh203 0:7798270c1f52 34
emh203 0:7798270c1f52 35 DigitalOut TEMP_SENSE_CS(p19);
emh203 0:7798270c1f52 36
emh203 0:7798270c1f52 37 DigitalIn LCD_SWITCH(p20);
emh203 0:7798270c1f52 38
emh203 0:7798270c1f52 39 MODSERIAL RS232_0(p9, p10, 1024, 1024);
emh203 0:7798270c1f52 40
emh203 0:7798270c1f52 41 MODSERIAL RS232_1(p28, p27, 1024, 1024);
emh203 0:7798270c1f52 42
emh203 0:7798270c1f52 43 // Make TX buffer 1024bytes and RX buffer use 512bytes.
emh203 0:7798270c1f52 44 MODSERIAL PC(USBTX, USBRX, 1024, 1024); // tx, rx
emh203 0:7798270c1f52 45
emh203 0:7798270c1f52 46 //Local Variables
emh203 0:7798270c1f52 47
emh203 0:7798270c1f52 48
emh203 0:7798270c1f52 49 static uint8_t HeaterBits = 0;
emh203 0:7798270c1f52 50
emh203 0:7798270c1f52 51 static uint16_t SolenoidBits = 0;
emh203 0:7798270c1f52 52
emh203 0:7798270c1f52 53 static uint8_t DigitalOutputBits = 0;
emh203 0:7798270c1f52 54
emh203 0:7798270c1f52 55 Timeout BuzzTimeout;
emh203 0:7798270c1f52 56
emh203 0:7798270c1f52 57 static uint16_t Thermocouple_FAULT = 0;
emh203 0:7798270c1f52 58
emh203 0:7798270c1f52 59 static uint16_t Thermocouple_SCV = 0;
emh203 0:7798270c1f52 60
emh203 0:7798270c1f52 61 static uint16_t Thermocouple_SCG = 0;
emh203 0:7798270c1f52 62
emh203 0:7798270c1f52 63 static uint16_t Thermocouple_OC= 0;
emh203 0:7798270c1f52 64
emh203 0:7798270c1f52 65 static float Temperature[12];
emh203 0:7798270c1f52 66
emh203 0:7798270c1f52 67 static float InternalTemperature[12];
emh203 0:7798270c1f52 68
emh203 0:7798270c1f52 69 static uint16_t ReadRawADC(uint8_t Channel);
emh203 0:7798270c1f52 70
emh203 0:7798270c1f52 71
emh203 0:7798270c1f52 72 //Local Functions
emh203 0:7798270c1f52 73
emh203 0:7798270c1f52 74 void InitTerminal();
emh203 0:7798270c1f52 75
emh203 0:7798270c1f52 76 void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data);
emh203 0:7798270c1f52 77
emh203 0:7798270c1f52 78
emh203 0:7798270c1f52 79
emh203 0:7798270c1f52 80 void InitChemBox()
emh203 0:7798270c1f52 81 {
emh203 0:7798270c1f52 82
emh203 0:7798270c1f52 83 AIO_ADC1_CS = 1;
emh203 0:7798270c1f52 84
emh203 0:7798270c1f52 85 AIO_ADC2_CS = 1;
emh203 0:7798270c1f52 86
emh203 0:7798270c1f52 87 BUZZER_CONTROL.period_ms(1.0);
emh203 0:7798270c1f52 88
emh203 0:7798270c1f52 89 MCU_SR_CLEAR = 1;
emh203 0:7798270c1f52 90
emh203 0:7798270c1f52 91 AIO_ADC1_CS = 1;
emh203 0:7798270c1f52 92
emh203 0:7798270c1f52 93 AIO_ADC2_CS = 1;
emh203 0:7798270c1f52 94
emh203 0:7798270c1f52 95 MFC_POWER_CONTROL = 0;
emh203 0:7798270c1f52 96
emh203 0:7798270c1f52 97 FAN_CONTROL.period_us(1000);
emh203 0:7798270c1f52 98
emh203 0:7798270c1f52 99 FAN_CONTROL.write(0);
emh203 0:7798270c1f52 100
emh203 0:7798270c1f52 101 SPI1.format(8,0);
emh203 0:7798270c1f52 102
emh203 0:7798270c1f52 103 SPI1.frequency(4000000);
emh203 0:7798270c1f52 104
emh203 0:7798270c1f52 105 MCU_SR_LOAD = 0;
emh203 0:7798270c1f52 106
emh203 0:7798270c1f52 107 SPI0.format(8,0);
emh203 0:7798270c1f52 108
emh203 0:7798270c1f52 109 SPI0.frequency(4000000);
emh203 0:7798270c1f52 110
emh203 0:7798270c1f52 111 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 112
emh203 0:7798270c1f52 113 TEMP_SENSE_ADDRESS = 0;
emh203 0:7798270c1f52 114
emh203 0:7798270c1f52 115 TEMP_SENSE_CS = 1;
emh203 0:7798270c1f52 116
emh203 0:7798270c1f52 117 HeaterBits = 0;
emh203 0:7798270c1f52 118
emh203 0:7798270c1f52 119 SolenoidBits = 0;
emh203 0:7798270c1f52 120
emh203 0:7798270c1f52 121 DigitalOutputBits = 0;
emh203 0:7798270c1f52 122
emh203 0:7798270c1f52 123 Thermocouple_FAULT = 0;
emh203 0:7798270c1f52 124
emh203 0:7798270c1f52 125 Thermocouple_SCV = 0;
emh203 0:7798270c1f52 126
emh203 0:7798270c1f52 127 Thermocouple_SCG = 0;
emh203 0:7798270c1f52 128
emh203 0:7798270c1f52 129 Thermocouple_OC= 0;
emh203 0:7798270c1f52 130
emh203 0:7798270c1f52 131 InitTerminal();
emh203 0:7798270c1f52 132
emh203 0:7798270c1f52 133 GFX_Init();
emh203 0:7798270c1f52 134 }
emh203 0:7798270c1f52 135
emh203 0:7798270c1f52 136
emh203 0:7798270c1f52 137 void SetFanSpeed(uint8_t S)
emh203 0:7798270c1f52 138 {
emh203 0:7798270c1f52 139 if(S>100)
emh203 0:7798270c1f52 140 S = 100;
emh203 0:7798270c1f52 141
emh203 0:7798270c1f52 142 FAN_CONTROL = (float)(S)/100.0;
emh203 0:7798270c1f52 143
emh203 0:7798270c1f52 144 }
emh203 0:7798270c1f52 145
emh203 0:7798270c1f52 146 void EnableFan()
emh203 0:7798270c1f52 147 {
emh203 0:7798270c1f52 148 SetFanSpeed(100);
emh203 0:7798270c1f52 149 }
emh203 0:7798270c1f52 150
emh203 0:7798270c1f52 151 void DisableFan()
emh203 0:7798270c1f52 152 {
emh203 0:7798270c1f52 153 SetFanSpeed(0);
emh203 0:7798270c1f52 154 }
emh203 0:7798270c1f52 155
emh203 0:7798270c1f52 156 void BuzzOff()
emh203 0:7798270c1f52 157 {
emh203 0:7798270c1f52 158 BUZZER_CONTROL = 0;
emh203 0:7798270c1f52 159 }
emh203 0:7798270c1f52 160
emh203 0:7798270c1f52 161 void Buzz(float Time)
emh203 0:7798270c1f52 162 {
emh203 0:7798270c1f52 163 BUZZER_CONTROL = 0.5;
emh203 0:7798270c1f52 164 BuzzTimeout.attach(&BuzzOff, Time);
emh203 0:7798270c1f52 165
emh203 0:7798270c1f52 166 }
emh203 0:7798270c1f52 167
emh203 0:7798270c1f52 168
emh203 0:7798270c1f52 169 void EnableHeater(uint8_t RelayIndex)
emh203 0:7798270c1f52 170 {
emh203 0:7798270c1f52 171 HeaterBits |= (1<<RelayIndex);
emh203 0:7798270c1f52 172 }
emh203 0:7798270c1f52 173
emh203 0:7798270c1f52 174 void DisableHeater(uint8_t RelayIndex)
emh203 0:7798270c1f52 175 {
emh203 0:7798270c1f52 176 HeaterBits &= ~(1<<RelayIndex);
emh203 0:7798270c1f52 177 }
emh203 0:7798270c1f52 178
emh203 0:7798270c1f52 179 void EnableSolenoidValve(uint8_t SolenoidIndex)
emh203 0:7798270c1f52 180 {
emh203 0:7798270c1f52 181 SolenoidBits |= (1<<SolenoidIndex);
emh203 0:7798270c1f52 182 }
emh203 0:7798270c1f52 183
emh203 0:7798270c1f52 184 void DisableSolenoidValue(uint8_t SolenoidIndex)
emh203 0:7798270c1f52 185 {
emh203 0:7798270c1f52 186 SolenoidBits &= ~(1<<SolenoidIndex);
emh203 0:7798270c1f52 187 }
emh203 0:7798270c1f52 188
emh203 0:7798270c1f52 189 void DisableAllHeatersAndSolenoids()
emh203 0:7798270c1f52 190 {
emh203 0:7798270c1f52 191
emh203 0:7798270c1f52 192 SolenoidBits = 0;
emh203 0:7798270c1f52 193 HeaterBits = 0;
emh203 0:7798270c1f52 194
emh203 0:7798270c1f52 195 MCU_SR_CLEAR = 1;
emh203 0:7798270c1f52 196
emh203 0:7798270c1f52 197 MCU_SR_CLEAR = 0;
emh203 0:7798270c1f52 198
emh203 0:7798270c1f52 199 MCU_SR_CLEAR = 1;
emh203 0:7798270c1f52 200
emh203 0:7798270c1f52 201 MCU_SR_LOAD = 1;
emh203 0:7798270c1f52 202
emh203 0:7798270c1f52 203 MCU_SR_LOAD = 0;
emh203 0:7798270c1f52 204 }
emh203 0:7798270c1f52 205
emh203 0:7798270c1f52 206 void EnableMiscDigitalOutput(uint8_t DigitalOutIndex)
emh203 0:7798270c1f52 207 {
emh203 0:7798270c1f52 208 DigitalOutputBits |= (1<<DigitalOutIndex);
emh203 0:7798270c1f52 209 }
emh203 0:7798270c1f52 210
emh203 0:7798270c1f52 211 void DisableMiscDigitalOutput(uint8_t DigitalOutIndex)
emh203 0:7798270c1f52 212 {
emh203 0:7798270c1f52 213 DigitalOutputBits &= ~(1<<DigitalOutIndex);
emh203 0:7798270c1f52 214 }
emh203 0:7798270c1f52 215
emh203 0:7798270c1f52 216 void FlushDigitalIO()
emh203 0:7798270c1f52 217 {
emh203 0:7798270c1f52 218 SPI1.format(8,0);
emh203 0:7798270c1f52 219
emh203 0:7798270c1f52 220 SPI1.write((SolenoidBits >> 8) & 0xFF);
emh203 0:7798270c1f52 221 SPI1.write(SolenoidBits & 0xFF);
emh203 0:7798270c1f52 222 SPI1.write(HeaterBits & 0xFF);
emh203 0:7798270c1f52 223 SPI1.write(DigitalOutputBits & 0xFF);
emh203 0:7798270c1f52 224
emh203 0:7798270c1f52 225 MCU_SR_LOAD = 1;
emh203 0:7798270c1f52 226 MCU_SR_LOAD = 0;
emh203 0:7798270c1f52 227 }
emh203 0:7798270c1f52 228
emh203 0:7798270c1f52 229 //Make sure to call ReadThermocouple befor eyou call this so internal variables are updated
emh203 0:7798270c1f52 230 uint16_t ReadThermocouple_OC()
emh203 0:7798270c1f52 231 {
emh203 0:7798270c1f52 232 return Thermocouple_OC;
emh203 0:7798270c1f52 233 }
emh203 0:7798270c1f52 234 //Make sure to call ReadThermocouple befor eyou call this so internal variables are updated
emh203 0:7798270c1f52 235 uint16_t ReadThermocouple_SCG()
emh203 0:7798270c1f52 236 {
emh203 0:7798270c1f52 237 return Thermocouple_SCG;
emh203 0:7798270c1f52 238 }
emh203 0:7798270c1f52 239 //Make sure to call ReadThermocouple befor eyou call this so internal variables are updated
emh203 0:7798270c1f52 240 uint16_t ReadThermocouple_SCV()
emh203 0:7798270c1f52 241 {
emh203 0:7798270c1f52 242 return Thermocouple_SCV;
emh203 0:7798270c1f52 243 }
emh203 0:7798270c1f52 244 //Make sure to call ReadThermocouple befor eyou call this so internal variables are updated
emh203 0:7798270c1f52 245 uint16_t ReadThermocouple_FAULT()
emh203 0:7798270c1f52 246 {
emh203 0:7798270c1f52 247 return Thermocouple_FAULT;
emh203 0:7798270c1f52 248 }
emh203 0:7798270c1f52 249
emh203 0:7798270c1f52 250
emh203 0:7798270c1f52 251 float ReadInternalTemperature(uint8_t ThermocoupleIndex)
emh203 0:7798270c1f52 252 {
emh203 0:7798270c1f52 253 ReadThermocouple(ThermocoupleIndex); //this will yank out the Data
emh203 0:7798270c1f52 254 return InternalTemperature[ThermocoupleIndex];
emh203 0:7798270c1f52 255 }
emh203 0:7798270c1f52 256
emh203 0:7798270c1f52 257
emh203 0:7798270c1f52 258
emh203 0:7798270c1f52 259 float ReadThermocouple(uint8_t ThermocoupleIndex)
emh203 0:7798270c1f52 260 {
emh203 0:7798270c1f52 261 uint8_t i=0;
emh203 0:7798270c1f52 262 uint32_t ThermocoupleData = 0;
emh203 0:7798270c1f52 263 uint8_t TempData[4];
emh203 0:7798270c1f52 264
emh203 0:7798270c1f52 265 int16_t InternalTemp = 0;
emh203 0:7798270c1f52 266 int16_t ThermocoupleTemp = 0;
emh203 0:7798270c1f52 267
emh203 0:7798270c1f52 268 //reset SPi format
emh203 0:7798270c1f52 269 SPI1.format(8,0);
emh203 0:7798270c1f52 270
emh203 0:7798270c1f52 271 TEMP_SENSE_ADDRESS = ThermocoupleIndex & 0x1f;
emh203 0:7798270c1f52 272
emh203 0:7798270c1f52 273 TEMP_SENSE_CS = 0;
emh203 0:7798270c1f52 274
emh203 0:7798270c1f52 275 for(i=0;i<4;i++)
emh203 0:7798270c1f52 276 TempData[i] = SPI1.write(0);
emh203 0:7798270c1f52 277
emh203 0:7798270c1f52 278 TEMP_SENSE_CS = 1;
emh203 0:7798270c1f52 279
emh203 0:7798270c1f52 280
emh203 0:7798270c1f52 281 ThermocoupleData = (uint32_t)(TempData[3]) |
emh203 0:7798270c1f52 282 (((uint32_t)(TempData[2]))<<8) |
emh203 0:7798270c1f52 283 (((uint32_t)(TempData[1]))<<16) |
emh203 0:7798270c1f52 284 (((uint32_t)(TempData[0]))<<24);
emh203 0:7798270c1f52 285
emh203 0:7798270c1f52 286
emh203 0:7798270c1f52 287 if(ThermocoupleData & 0x01)
emh203 0:7798270c1f52 288 Thermocouple_OC |= (1<<ThermocoupleIndex);
emh203 0:7798270c1f52 289 else
emh203 0:7798270c1f52 290 Thermocouple_OC &= ~(1<<ThermocoupleIndex);
emh203 0:7798270c1f52 291
emh203 0:7798270c1f52 292 if(ThermocoupleData & 0x02)
emh203 0:7798270c1f52 293 Thermocouple_SCG |= (1<<ThermocoupleIndex);
emh203 0:7798270c1f52 294 else
emh203 0:7798270c1f52 295 Thermocouple_SCG &= ~(1<<ThermocoupleIndex);
emh203 0:7798270c1f52 296
emh203 0:7798270c1f52 297 if(ThermocoupleData & 0x04)
emh203 0:7798270c1f52 298 Thermocouple_SCV |= (1<<ThermocoupleIndex);
emh203 0:7798270c1f52 299 else
emh203 0:7798270c1f52 300 Thermocouple_SCV &= ~(1<<ThermocoupleIndex);
emh203 0:7798270c1f52 301
emh203 0:7798270c1f52 302 if(ThermocoupleData & (1<<16))
emh203 0:7798270c1f52 303 Thermocouple_FAULT |= (1<<ThermocoupleIndex);
emh203 0:7798270c1f52 304 else
emh203 0:7798270c1f52 305 Thermocouple_FAULT &= ~(1<<ThermocoupleIndex);
emh203 0:7798270c1f52 306
emh203 0:7798270c1f52 307 if(ThermocoupleData & (1<<15))
emh203 0:7798270c1f52 308 InternalTemp = (int16_t) ( ( (ThermocoupleData>>4) & 0xFFF) | 0xF000); //Sign extend in this case.... we need to map a 12 bit signed number to 16-bits
emh203 0:7798270c1f52 309 else
emh203 0:7798270c1f52 310 InternalTemp = (int16_t)( ( (ThermocoupleData>>4) & 0xFFF));
emh203 0:7798270c1f52 311
emh203 0:7798270c1f52 312
emh203 0:7798270c1f52 313 if(ThermocoupleData & (0x10000000))
emh203 0:7798270c1f52 314 ThermocoupleTemp = (int16_t)(((ThermocoupleData>>18) & 0x2FFF) | 0xC000); //Sign extend in this case.... we need to map a 14 bit signed number to 16-bits
emh203 0:7798270c1f52 315 else
emh203 0:7798270c1f52 316 ThermocoupleTemp = (int16_t)(((ThermocoupleData>>18) & 0x2FFF));
emh203 0:7798270c1f52 317
emh203 0:7798270c1f52 318 Temperature[ThermocoupleIndex] = (float)ThermocoupleTemp/4.0;
emh203 0:7798270c1f52 319
emh203 0:7798270c1f52 320 InternalTemperature[ThermocoupleIndex] = (float)InternalTemp/16.0;;
emh203 0:7798270c1f52 321
emh203 0:7798270c1f52 322 return Temperature[ThermocoupleIndex];
emh203 0:7798270c1f52 323 }
emh203 0:7798270c1f52 324
emh203 0:7798270c1f52 325 float ReadMFC_AnalogInput(uint8_t Channel)
emh203 0:7798270c1f52 326 {
emh203 0:7798270c1f52 327 if(Channel > 7)
emh203 0:7798270c1f52 328 Channel = 7;
emh203 0:7798270c1f52 329
emh203 0:7798270c1f52 330 return ((float)(ReadRawADC(Channel)) /4095.0) * 5.0;
emh203 0:7798270c1f52 331
emh203 0:7798270c1f52 332 }
emh203 0:7798270c1f52 333
emh203 0:7798270c1f52 334 void EnableMFC_Power()
emh203 0:7798270c1f52 335 {
emh203 0:7798270c1f52 336 MFC_POWER_CONTROL = 1;
emh203 0:7798270c1f52 337 }
emh203 0:7798270c1f52 338
emh203 0:7798270c1f52 339 void DisableMFC_Power()
emh203 0:7798270c1f52 340 {
emh203 0:7798270c1f52 341 MFC_POWER_CONTROL = 0;
emh203 0:7798270c1f52 342 }
emh203 0:7798270c1f52 343
emh203 0:7798270c1f52 344
emh203 0:7798270c1f52 345 float ReadMISC_AnalogInput(uint8_t Channel)
emh203 0:7798270c1f52 346 {
emh203 0:7798270c1f52 347
emh203 0:7798270c1f52 348 if(Channel > 3)
emh203 0:7798270c1f52 349 Channel = 3;
emh203 0:7798270c1f52 350
emh203 0:7798270c1f52 351 return ((float)(ReadRawADC(Channel + 9)) /4095.0) * 5.0;
emh203 0:7798270c1f52 352
emh203 0:7798270c1f52 353 }
emh203 0:7798270c1f52 354
emh203 0:7798270c1f52 355 float Read4to20(uint8_t Channel)
emh203 0:7798270c1f52 356 {
emh203 0:7798270c1f52 357
emh203 0:7798270c1f52 358 if(Channel > 1)
emh203 0:7798270c1f52 359 Channel = 1;
emh203 0:7798270c1f52 360
emh203 1:d64ac853223c 361 return (((float)(ReadRawADC(Channel + 7)) /4095.0) * 5.0) / 82;
emh203 0:7798270c1f52 362
emh203 0:7798270c1f52 363 }
emh203 0:7798270c1f52 364
emh203 0:7798270c1f52 365
emh203 0:7798270c1f52 366 static uint16_t ReadRawADC(uint8_t Channel)
emh203 0:7798270c1f52 367 {
emh203 0:7798270c1f52 368 uint8_t ControlByte[3];
emh203 0:7798270c1f52 369 uint8_t ADC_Data[3];
emh203 0:7798270c1f52 370 uint16_t V;
emh203 0:7798270c1f52 371
emh203 0:7798270c1f52 372 SPI0.format(8,0); //The ADC requires mode 0,0
emh203 0:7798270c1f52 373
emh203 0:7798270c1f52 374 /*See Microchip manual DS21298E-page 21*/
emh203 0:7798270c1f52 375
emh203 0:7798270c1f52 376 ControlByte[0] = (((Channel&0x07)>>2) & 0x01) | (3<<1);
emh203 0:7798270c1f52 377 ControlByte[1] = Channel<<6;
emh203 0:7798270c1f52 378 ControlByte[2] = 0;
emh203 0:7798270c1f52 379
emh203 0:7798270c1f52 380
emh203 0:7798270c1f52 381 if(Channel<8)
emh203 0:7798270c1f52 382 AIO_ADC1_CS = 0;
emh203 0:7798270c1f52 383 else
emh203 0:7798270c1f52 384 AIO_ADC2_CS = 0;
emh203 0:7798270c1f52 385
emh203 0:7798270c1f52 386 //unroll the loop
emh203 0:7798270c1f52 387 ADC_Data[0] = SPI0.write(ControlByte[0]);
emh203 0:7798270c1f52 388 ADC_Data[1] = SPI0.write(ControlByte[1]);
emh203 0:7798270c1f52 389 ADC_Data[2] = SPI0.write(ControlByte[2]);
emh203 0:7798270c1f52 390
emh203 0:7798270c1f52 391 AIO_ADC1_CS = 1;
emh203 0:7798270c1f52 392 AIO_ADC2_CS = 1;
emh203 0:7798270c1f52 393
emh203 0:7798270c1f52 394
emh203 0:7798270c1f52 395 V = ((uint16_t)(ADC_Data[1])<<8 | (uint16_t)(ADC_Data[2])) & 0xFFF;
emh203 0:7798270c1f52 396
emh203 0:7798270c1f52 397 return (V);
emh203 0:7798270c1f52 398
emh203 0:7798270c1f52 399 }
emh203 0:7798270c1f52 400
emh203 0:7798270c1f52 401
emh203 0:7798270c1f52 402 void WriteMFC_AnalogOut(uint8_t Channel,float Value)
emh203 0:7798270c1f52 403 {
emh203 0:7798270c1f52 404
emh203 0:7798270c1f52 405 if(Channel>7)
emh203 0:7798270c1f52 406 Channel = 7;
emh203 0:7798270c1f52 407
emh203 0:7798270c1f52 408 if(Value >5.0)
emh203 0:7798270c1f52 409 Value = 5.0;
emh203 0:7798270c1f52 410
emh203 0:7798270c1f52 411 if(Value<0.0)
emh203 0:7798270c1f52 412 Value = 0.0;
emh203 0:7798270c1f52 413
emh203 0:7798270c1f52 414 WriteRAW_DAC_Value(Channel,(uint16_t)((Value/5.0) * 4095));
emh203 0:7798270c1f52 415
emh203 0:7798270c1f52 416 }
emh203 0:7798270c1f52 417
emh203 0:7798270c1f52 418 void WriteMISC_AnalogOut(uint8_t Channel,float Value)
emh203 0:7798270c1f52 419 {
emh203 0:7798270c1f52 420 if(Channel>3)
emh203 0:7798270c1f52 421 Channel = 3;
emh203 0:7798270c1f52 422
emh203 0:7798270c1f52 423 if(Value >5.0)
emh203 0:7798270c1f52 424 Value = 5.0;
emh203 0:7798270c1f52 425
emh203 0:7798270c1f52 426 if(Value<0.0)
emh203 0:7798270c1f52 427 Value = 0.0;
emh203 0:7798270c1f52 428
emh203 0:7798270c1f52 429 WriteRAW_DAC_Value(8+Channel,(uint16_t)((Value/5.0)*4095));
emh203 0:7798270c1f52 430 }
emh203 0:7798270c1f52 431
emh203 0:7798270c1f52 432
emh203 0:7798270c1f52 433 void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data)
emh203 0:7798270c1f52 434 {
emh203 0:7798270c1f52 435
emh203 0:7798270c1f52 436 uint16_t DataOut;
emh203 0:7798270c1f52 437
emh203 0:7798270c1f52 438 if(Channel<8)
emh203 0:7798270c1f52 439 AIO_DAC1_CS = 0;
emh203 0:7798270c1f52 440 else
emh203 0:7798270c1f52 441 AIO_DAC2_CS = 0;
emh203 0:7798270c1f52 442
emh203 0:7798270c1f52 443 SPI0.format(8,1); //The DAC requires mode 0,1
emh203 0:7798270c1f52 444
emh203 0:7798270c1f52 445 DataOut = ((uint16_t)(Channel) & 0x7)<<12 | (Data & 0xFFF);
emh203 0:7798270c1f52 446
emh203 0:7798270c1f52 447 SPI0.write((DataOut>>8)&0xFF);
emh203 0:7798270c1f52 448 SPI0.write(DataOut&0xFF);
emh203 0:7798270c1f52 449
emh203 0:7798270c1f52 450 AIO_DAC1_CS = 1;
emh203 0:7798270c1f52 451 AIO_DAC2_CS = 1;
emh203 0:7798270c1f52 452
emh203 0:7798270c1f52 453 }
emh203 0:7798270c1f52 454
emh203 0:7798270c1f52 455
emh203 0:7798270c1f52 456
emh203 0:7798270c1f52 457
emh203 0:7798270c1f52 458 #define MAX_TERMINAL_LINE_CHARS 128
emh203 0:7798270c1f52 459 #define MAX_TERMINAL_CMD_CHARS 64
emh203 0:7798270c1f52 460
emh203 0:7798270c1f52 461 #ifndef TRUE
emh203 0:7798270c1f52 462 #define TRUE 1
emh203 0:7798270c1f52 463 #endif
emh203 0:7798270c1f52 464
emh203 0:7798270c1f52 465 #ifndef FALSE
emh203 0:7798270c1f52 466 #define FALSE 0
emh203 0:7798270c1f52 467 #endif
emh203 0:7798270c1f52 468
emh203 0:7798270c1f52 469 typedef void (*TerminalCallback)(char *);
emh203 0:7798270c1f52 470
emh203 0:7798270c1f52 471
emh203 0:7798270c1f52 472 typedef struct
emh203 0:7798270c1f52 473 {
emh203 0:7798270c1f52 474 const char *CommandString;
emh203 0:7798270c1f52 475 TerminalCallback Callback;
emh203 0:7798270c1f52 476 const char *HelpString;
emh203 0:7798270c1f52 477
emh203 0:7798270c1f52 478 } TerminalCallbackRecord;
emh203 0:7798270c1f52 479
emh203 0:7798270c1f52 480 //Callback function prototypes
emh203 0:7798270c1f52 481 void TerminalCmd_Help(char *arg);
emh203 0:7798270c1f52 482 void TerminalCmd_Stub(char *arg);
emh203 0:7798270c1f52 483 void TerminalCmd_EnableHeater(char *arg);
emh203 0:7798270c1f52 484 void TerminalCmd_DisableHeater(char *arg);
emh203 0:7798270c1f52 485 void TerminalCmd_EnableSolenoidValve(char *arg);
emh203 0:7798270c1f52 486 void TerminalCmd_DisableSolenoidValue(char *arg);
emh203 0:7798270c1f52 487 void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg);
emh203 0:7798270c1f52 488 void TerminalCmd_EnableMiscDigitalOutput(char *arg);
emh203 0:7798270c1f52 489 void TerminalCmd_DisableMiscDigitalOutput(char *arg);
emh203 0:7798270c1f52 490 void TerminalCmd_FlushDigitalIO(char *arg);
emh203 0:7798270c1f52 491 void TerminalCmd_FanOn(char *arg);
emh203 0:7798270c1f52 492 void TerminalCmd_FanOff(char *arg);
emh203 0:7798270c1f52 493 void TerminalCmd_Buzz(char *arg);
emh203 0:7798270c1f52 494 void TerminalCmd_T(char *arg);
emh203 0:7798270c1f52 495 void TerminalCmd_MFCI(char *arg);
emh203 0:7798270c1f52 496 void TerminalCmd_MFCO(char *arg);
emh203 0:7798270c1f52 497 void TerminalCmd_4TO20(char *arg);
emh203 0:7798270c1f52 498 void TerminalCmd_AIN(char *arg);
emh203 0:7798270c1f52 499 void TerminalCmd_MFCON(char *arg);
emh203 0:7798270c1f52 500 void TerminalCmd_MFCOFF(char *arg);
emh203 0:7798270c1f52 501 void TerminalCmd_AOUT(char *arg);
emh203 0:7798270c1f52 502 void TerminalCmd_Reset(char *arg);
emh203 0:7798270c1f52 503
emh203 0:7798270c1f52 504 //Populate this array with the callback functions and their terminal command string
emh203 0:7798270c1f52 505 TerminalCallbackRecord MyTerminalCallbackRecords[] ={ {"reset",TerminalCmd_Reset,"Resets the CHEM box"},
emh203 0:7798270c1f52 506
emh203 0:7798270c1f52 507 {"help",TerminalCmd_Help,"Lists available commands"},
emh203 0:7798270c1f52 508
emh203 0:7798270c1f52 509 {"EH",TerminalCmd_EnableHeater,"Enables a heater channel. Argument should be between 0 and 7. Outputs will update when a FDIO command is issued"},
emh203 0:7798270c1f52 510
emh203 0:7798270c1f52 511 {"DH",TerminalCmd_DisableHeater,"Disables a heater channel. Argument should be between 0 and 7. Outputs will update when a FDIO command is issued"},
emh203 0:7798270c1f52 512
emh203 0:7798270c1f52 513 {"ESV",TerminalCmd_EnableSolenoidValve,"Enables a solenoid channel. Argument should be between 0 and 11. Outputs will update when a FDIO command is issued"},
emh203 0:7798270c1f52 514
emh203 0:7798270c1f52 515 {"DSV",TerminalCmd_DisableSolenoidValue,"Disables a solenoid channel. Argument should be between 0 and 11. Outputs will update when a FFDIO command is issued"},
emh203 0:7798270c1f52 516
emh203 0:7798270c1f52 517 {"DAHAS",TerminalCmd_DisableAllHeatersAndSolenoids,"Disables all heaters and solenoids. Command is immediately executed."},
emh203 0:7798270c1f52 518
emh203 0:7798270c1f52 519 {"EMDO",TerminalCmd_EnableMiscDigitalOutput,"Enables a misc. digital output. Argument should be between 0 and 3. Output will update when a FDIO command is issued"},
emh203 0:7798270c1f52 520
emh203 0:7798270c1f52 521 {"DMDO",TerminalCmd_DisableMiscDigitalOutput,"Enables a misc. digital output. Argument should be between 0 and 3. Output will update when a FDIO command is issued"},
emh203 0:7798270c1f52 522
emh203 0:7798270c1f52 523 {"FDIO",TerminalCmd_FlushDigitalIO,"Updates the all of the digital IO channels"},
emh203 0:7798270c1f52 524
emh203 0:7798270c1f52 525 {"FON",TerminalCmd_FanOn,"Turns on the fans"},
emh203 0:7798270c1f52 526
emh203 0:7798270c1f52 527 {"FOFF",TerminalCmd_FanOff,"Turns off the fans"},
emh203 0:7798270c1f52 528
emh203 0:7798270c1f52 529 {"BUZZ",TerminalCmd_Buzz,"Buzz for a little bit. Argument should be a floating point number representing the number of seconds to buzz"},
emh203 0:7798270c1f52 530
emh203 0:7798270c1f52 531 {"T",TerminalCmd_T,"Read thermocouple channel"},
emh203 0:7798270c1f52 532
emh203 0:7798270c1f52 533 {"MFCI",TerminalCmd_MFCI,"Reads in voltage from MFC channel"},
emh203 0:7798270c1f52 534
emh203 0:7798270c1f52 535 {"MFCO",TerminalCmd_MFCO,"Sets voltage at MFC output channel. First argument should be the channel. Second argument should be the voltage. I.E. MFCO 1.45"},
emh203 0:7798270c1f52 536
emh203 0:7798270c1f52 537 {"AOUT",TerminalCmd_AOUT,"Sets voltage at misc. output channel. First argument should be the channel. Second argument should be the voltage. I.E. AOUT 3.211"},
emh203 0:7798270c1f52 538
emh203 0:7798270c1f52 539 {"4TO20",TerminalCmd_4TO20,"Reads a 4 to 20 mA channel"},
emh203 0:7798270c1f52 540
emh203 0:7798270c1f52 541 {"AIN",TerminalCmd_AIN,"Reads a general purpose analog in channel"},
emh203 0:7798270c1f52 542
emh203 0:7798270c1f52 543 {"MFCON",TerminalCmd_MFCON,"Turns on the MFC power"},
emh203 0:7798270c1f52 544
emh203 0:7798270c1f52 545 {"MFCOFF",TerminalCmd_MFCOFF,"Turns off the MFC power"}
emh203 0:7798270c1f52 546 };
emh203 0:7798270c1f52 547
emh203 0:7798270c1f52 548
emh203 0:7798270c1f52 549 extern "C" void mbed_reset();
emh203 0:7798270c1f52 550
emh203 0:7798270c1f52 551 void TerminalCmd_Reset(char *arg)
emh203 0:7798270c1f52 552 {
emh203 0:7798270c1f52 553 mbed_reset();
emh203 0:7798270c1f52 554 }
emh203 0:7798270c1f52 555
emh203 0:7798270c1f52 556 void TerminalCmd_Stub(char *arg)
emh203 0:7798270c1f52 557 {
emh203 0:7798270c1f52 558 PC.printf("stub \r\n");
emh203 0:7798270c1f52 559 }
emh203 0:7798270c1f52 560
emh203 0:7798270c1f52 561 void TerminalCmd_MFCI(char *arg)
emh203 0:7798270c1f52 562 {
emh203 0:7798270c1f52 563 int Channel = -1;
emh203 0:7798270c1f52 564 float Data;
emh203 0:7798270c1f52 565
emh203 0:7798270c1f52 566 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 567 {
emh203 0:7798270c1f52 568 if(Channel>=0 && Channel <=6)
emh203 0:7798270c1f52 569 {
emh203 0:7798270c1f52 570 Data = ReadMFC_AnalogInput(Channel);
emh203 0:7798270c1f52 571 PC.printf("MFCI:%d:%.3f",Channel,Data);
emh203 0:7798270c1f52 572 }
emh203 0:7798270c1f52 573 else
emh203 0:7798270c1f52 574 {
emh203 0:7798270c1f52 575 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 6",Channel);
emh203 0:7798270c1f52 576 }
emh203 0:7798270c1f52 577 }
emh203 0:7798270c1f52 578 else
emh203 0:7798270c1f52 579 {
emh203 0:7798270c1f52 580 for(Channel = 0; Channel<=6; Channel++)
emh203 0:7798270c1f52 581 {
emh203 0:7798270c1f52 582 Data = ReadMFC_AnalogInput(Channel);
emh203 0:7798270c1f52 583 PC.printf("MFCI:%d:%.3f\r\n",Channel,Data);
emh203 0:7798270c1f52 584 }
emh203 0:7798270c1f52 585 }
emh203 0:7798270c1f52 586 }
emh203 0:7798270c1f52 587
emh203 0:7798270c1f52 588 void TerminalCmd_MFCON(char *arg)
emh203 0:7798270c1f52 589 {
emh203 0:7798270c1f52 590 EnableMFC_Power();
emh203 0:7798270c1f52 591 }
emh203 0:7798270c1f52 592
emh203 0:7798270c1f52 593
emh203 0:7798270c1f52 594 void TerminalCmd_MFCOFF(char *arg)
emh203 0:7798270c1f52 595 {
emh203 0:7798270c1f52 596 DisableMFC_Power();
emh203 0:7798270c1f52 597 }
emh203 0:7798270c1f52 598
emh203 0:7798270c1f52 599
emh203 0:7798270c1f52 600 void TerminalCmd_MFCO(char *arg)
emh203 0:7798270c1f52 601 {
emh203 0:7798270c1f52 602 int Channel = -1;
emh203 0:7798270c1f52 603 float Data = 0.0;
emh203 0:7798270c1f52 604
emh203 0:7798270c1f52 605 if(sscanf(arg,"%d %f",&Channel,&Data) == 2)
emh203 0:7798270c1f52 606 {
emh203 0:7798270c1f52 607 if(Channel>=0 && Channel <=7)
emh203 0:7798270c1f52 608 {
emh203 0:7798270c1f52 609 WriteMFC_AnalogOut(Channel,Data);
emh203 0:7798270c1f52 610 }
emh203 0:7798270c1f52 611 else
emh203 0:7798270c1f52 612 {
emh203 0:7798270c1f52 613 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel);
emh203 0:7798270c1f52 614 }
emh203 0:7798270c1f52 615 }
emh203 0:7798270c1f52 616 else
emh203 0:7798270c1f52 617 {
emh203 0:7798270c1f52 618 PC.printf("Bad argument... %s. Channel should be an integer between 0 and 7 and value should be a float between 0.0 and 5.0. i.e. MFCO 2 4.45",arg);
emh203 0:7798270c1f52 619 }
emh203 0:7798270c1f52 620 }
emh203 0:7798270c1f52 621
emh203 0:7798270c1f52 622 void TerminalCmd_AOUT(char *arg)
emh203 0:7798270c1f52 623 {
emh203 0:7798270c1f52 624 int Channel = -1;
emh203 0:7798270c1f52 625 float Data = 0.0;
emh203 0:7798270c1f52 626
emh203 0:7798270c1f52 627 if(sscanf(arg,"%d %f",&Channel,&Data) == 2)
emh203 0:7798270c1f52 628 {
emh203 0:7798270c1f52 629 if(Channel>=0 && Channel <=3)
emh203 0:7798270c1f52 630 {
emh203 0:7798270c1f52 631 WriteMISC_AnalogOut(Channel,Data);
emh203 0:7798270c1f52 632 }
emh203 0:7798270c1f52 633 else
emh203 0:7798270c1f52 634 {
emh203 0:7798270c1f52 635 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel);
emh203 0:7798270c1f52 636 }
emh203 0:7798270c1f52 637 }
emh203 0:7798270c1f52 638 else
emh203 0:7798270c1f52 639 {
emh203 0:7798270c1f52 640 PC.printf("Bad argument... %s. Channel should be an integer between 0 and 7 and value should be a float between 0.0 and 5.0. i.e. AOUT 1 1.25",arg);
emh203 0:7798270c1f52 641 }
emh203 0:7798270c1f52 642 }
emh203 0:7798270c1f52 643
emh203 0:7798270c1f52 644 void TerminalCmd_4TO20(char *arg)
emh203 0:7798270c1f52 645 {
emh203 0:7798270c1f52 646 int Channel = -1;
emh203 0:7798270c1f52 647 float Data;
emh203 0:7798270c1f52 648
emh203 0:7798270c1f52 649 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 650 {
emh203 0:7798270c1f52 651 if(Channel>=0 && Channel <=1)
emh203 0:7798270c1f52 652 {
emh203 0:7798270c1f52 653 Data = Read4to20(Channel);
emh203 0:7798270c1f52 654 PC.printf("4TO20:%d:%.3f",Channel,Data);
emh203 0:7798270c1f52 655 }
emh203 0:7798270c1f52 656 else
emh203 0:7798270c1f52 657 {
emh203 0:7798270c1f52 658 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel);
emh203 0:7798270c1f52 659 }
emh203 0:7798270c1f52 660 }
emh203 0:7798270c1f52 661 else
emh203 0:7798270c1f52 662 {
emh203 0:7798270c1f52 663
emh203 0:7798270c1f52 664 for(Channel = 0;Channel<=1;Channel++)
emh203 0:7798270c1f52 665 {
emh203 0:7798270c1f52 666 Data = Read4to20(Channel);
emh203 1:d64ac853223c 667 PC.printf("4TO20:%d:%.5f\r\n",Channel,Data);
emh203 0:7798270c1f52 668 }
emh203 0:7798270c1f52 669
emh203 0:7798270c1f52 670 }
emh203 0:7798270c1f52 671
emh203 0:7798270c1f52 672
emh203 0:7798270c1f52 673 }
emh203 0:7798270c1f52 674
emh203 0:7798270c1f52 675 void TerminalCmd_AIN(char *arg)
emh203 0:7798270c1f52 676 {
emh203 0:7798270c1f52 677 int Channel = -1;
emh203 0:7798270c1f52 678 float Data;
emh203 0:7798270c1f52 679
emh203 0:7798270c1f52 680 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 681 {
emh203 0:7798270c1f52 682 if(Channel>=0 && Channel <=3)
emh203 0:7798270c1f52 683 {
emh203 0:7798270c1f52 684 Data = ReadMISC_AnalogInput(Channel);
emh203 0:7798270c1f52 685 PC.printf("AIN:%d:%.3f",Channel,Data);
emh203 0:7798270c1f52 686 }
emh203 0:7798270c1f52 687 else
emh203 0:7798270c1f52 688 {
emh203 0:7798270c1f52 689 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel);
emh203 0:7798270c1f52 690 }
emh203 0:7798270c1f52 691 }
emh203 0:7798270c1f52 692 else
emh203 0:7798270c1f52 693 {
emh203 0:7798270c1f52 694 for(Channel = 0;Channel<=3;Channel++)
emh203 0:7798270c1f52 695 {
emh203 0:7798270c1f52 696 Data = ReadMISC_AnalogInput(Channel);
emh203 0:7798270c1f52 697 PC.printf("AIN:%d:%.3f\r\n",Channel,Data);
emh203 0:7798270c1f52 698 }
emh203 0:7798270c1f52 699 }
emh203 0:7798270c1f52 700 }
emh203 0:7798270c1f52 701
emh203 0:7798270c1f52 702
emh203 0:7798270c1f52 703
emh203 0:7798270c1f52 704 void TerminalCmd_EnableHeater(char *arg)
emh203 0:7798270c1f52 705 {
emh203 0:7798270c1f52 706 int Channel = -1;
emh203 0:7798270c1f52 707
emh203 0:7798270c1f52 708 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 709 {
emh203 0:7798270c1f52 710 if(Channel>=0 && Channel <=7)
emh203 0:7798270c1f52 711 {
emh203 0:7798270c1f52 712 EnableHeater(Channel);
emh203 0:7798270c1f52 713 }
emh203 0:7798270c1f52 714 else
emh203 0:7798270c1f52 715 {
emh203 0:7798270c1f52 716 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel);
emh203 0:7798270c1f52 717 }
emh203 0:7798270c1f52 718 }
emh203 0:7798270c1f52 719 else
emh203 0:7798270c1f52 720 {
emh203 0:7798270c1f52 721 PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg);
emh203 0:7798270c1f52 722 }
emh203 0:7798270c1f52 723 }
emh203 0:7798270c1f52 724
emh203 0:7798270c1f52 725 void TerminalCmd_DisableHeater(char *arg)
emh203 0:7798270c1f52 726 {
emh203 0:7798270c1f52 727 int Channel = -1;
emh203 0:7798270c1f52 728
emh203 0:7798270c1f52 729 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 730 {
emh203 0:7798270c1f52 731 if(Channel>=0 && Channel <=7)
emh203 0:7798270c1f52 732 {
emh203 0:7798270c1f52 733 DisableHeater(Channel);
emh203 0:7798270c1f52 734 }
emh203 0:7798270c1f52 735 else
emh203 0:7798270c1f52 736 {
emh203 0:7798270c1f52 737 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel);
emh203 0:7798270c1f52 738 }
emh203 0:7798270c1f52 739 }
emh203 0:7798270c1f52 740 else
emh203 0:7798270c1f52 741 {
emh203 0:7798270c1f52 742 PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg);
emh203 0:7798270c1f52 743 }
emh203 0:7798270c1f52 744
emh203 0:7798270c1f52 745 }
emh203 0:7798270c1f52 746
emh203 0:7798270c1f52 747 void TerminalCmd_EnableSolenoidValve(char *arg)
emh203 0:7798270c1f52 748 {
emh203 0:7798270c1f52 749
emh203 0:7798270c1f52 750 int Channel = -1;
emh203 0:7798270c1f52 751
emh203 0:7798270c1f52 752 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 753 {
emh203 0:7798270c1f52 754 if(Channel>=0 && Channel <=11)
emh203 0:7798270c1f52 755 {
emh203 0:7798270c1f52 756 EnableSolenoidValve(Channel);
emh203 0:7798270c1f52 757 }
emh203 0:7798270c1f52 758 else
emh203 0:7798270c1f52 759 {
emh203 0:7798270c1f52 760 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel);
emh203 0:7798270c1f52 761 }
emh203 0:7798270c1f52 762 }
emh203 0:7798270c1f52 763 else
emh203 0:7798270c1f52 764 {
emh203 0:7798270c1f52 765 PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg);
emh203 0:7798270c1f52 766 }
emh203 0:7798270c1f52 767 }
emh203 0:7798270c1f52 768
emh203 0:7798270c1f52 769 void TerminalCmd_DisableSolenoidValue(char *arg)
emh203 0:7798270c1f52 770 {
emh203 0:7798270c1f52 771 int Channel = -1;
emh203 0:7798270c1f52 772
emh203 0:7798270c1f52 773 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 774 {
emh203 0:7798270c1f52 775 if( Channel >= 0 && Channel <= 11)
emh203 0:7798270c1f52 776 {
emh203 0:7798270c1f52 777 DisableSolenoidValue(Channel);
emh203 0:7798270c1f52 778 }
emh203 0:7798270c1f52 779 else
emh203 0:7798270c1f52 780 {
emh203 0:7798270c1f52 781 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel);
emh203 0:7798270c1f52 782 }
emh203 0:7798270c1f52 783 }
emh203 0:7798270c1f52 784 else
emh203 0:7798270c1f52 785 {
emh203 0:7798270c1f52 786 PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg);
emh203 0:7798270c1f52 787 }
emh203 0:7798270c1f52 788
emh203 0:7798270c1f52 789 }
emh203 0:7798270c1f52 790 void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg)
emh203 0:7798270c1f52 791 {
emh203 0:7798270c1f52 792
emh203 0:7798270c1f52 793 DisableAllHeatersAndSolenoids();
emh203 0:7798270c1f52 794
emh203 0:7798270c1f52 795 }
emh203 0:7798270c1f52 796
emh203 0:7798270c1f52 797 void TerminalCmd_EnableMiscDigitalOutput(char *arg)
emh203 0:7798270c1f52 798 {
emh203 0:7798270c1f52 799 int Channel = -1;
emh203 0:7798270c1f52 800
emh203 0:7798270c1f52 801 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 802 {
emh203 0:7798270c1f52 803 if(Channel>=0 && Channel <=3)
emh203 0:7798270c1f52 804 {
emh203 0:7798270c1f52 805 EnableMiscDigitalOutput(Channel);
emh203 0:7798270c1f52 806 }
emh203 0:7798270c1f52 807 else
emh203 0:7798270c1f52 808 {
emh203 0:7798270c1f52 809 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel);
emh203 0:7798270c1f52 810 }
emh203 0:7798270c1f52 811 }
emh203 0:7798270c1f52 812 else
emh203 0:7798270c1f52 813 {
emh203 0:7798270c1f52 814 PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg);
emh203 0:7798270c1f52 815 }
emh203 0:7798270c1f52 816
emh203 0:7798270c1f52 817 }
emh203 0:7798270c1f52 818
emh203 0:7798270c1f52 819 void TerminalCmd_DisableMiscDigitalOutput(char *arg)
emh203 0:7798270c1f52 820 {
emh203 0:7798270c1f52 821 int Channel = -1;
emh203 0:7798270c1f52 822
emh203 0:7798270c1f52 823 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 824 {
emh203 0:7798270c1f52 825 if(Channel>=0 && Channel <=3)
emh203 0:7798270c1f52 826 {
emh203 0:7798270c1f52 827 DisableMiscDigitalOutput(Channel);
emh203 0:7798270c1f52 828 }
emh203 0:7798270c1f52 829 else
emh203 0:7798270c1f52 830 {
emh203 0:7798270c1f52 831 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel);
emh203 0:7798270c1f52 832 }
emh203 0:7798270c1f52 833 }
emh203 0:7798270c1f52 834 else
emh203 0:7798270c1f52 835 {
emh203 0:7798270c1f52 836 PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg);
emh203 0:7798270c1f52 837 }
emh203 0:7798270c1f52 838
emh203 0:7798270c1f52 839 }
emh203 0:7798270c1f52 840
emh203 0:7798270c1f52 841 void TerminalCmd_FlushDigitalIO(char *arg)
emh203 0:7798270c1f52 842 {
emh203 0:7798270c1f52 843 FlushDigitalIO();
emh203 0:7798270c1f52 844 }
emh203 0:7798270c1f52 845
emh203 0:7798270c1f52 846 void TerminalCmd_FanOn(char *arg)
emh203 0:7798270c1f52 847 {
emh203 0:7798270c1f52 848 SetFanSpeed(100); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off
emh203 0:7798270c1f52 849 }
emh203 0:7798270c1f52 850
emh203 0:7798270c1f52 851 void TerminalCmd_FanOff(char *arg)
emh203 0:7798270c1f52 852 {
emh203 0:7798270c1f52 853 SetFanSpeed(0); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off
emh203 0:7798270c1f52 854 }
emh203 0:7798270c1f52 855
emh203 0:7798270c1f52 856 void TerminalCmd_Fan(char *arg)
emh203 0:7798270c1f52 857 {
emh203 0:7798270c1f52 858 int Speed = -1;
emh203 0:7798270c1f52 859
emh203 0:7798270c1f52 860 if(sscanf(arg,"%d",&Speed) == 1)
emh203 0:7798270c1f52 861 {
emh203 0:7798270c1f52 862 if(Speed>=0 && Speed<=100)
emh203 0:7798270c1f52 863 {
emh203 0:7798270c1f52 864 SetFanSpeed(Speed);
emh203 0:7798270c1f52 865 }
emh203 0:7798270c1f52 866 else
emh203 0:7798270c1f52 867 {
emh203 0:7798270c1f52 868 PC.printf("%d is an invalid speed. Speed should be between 0 and 100",Speed);
emh203 0:7798270c1f52 869 }
emh203 0:7798270c1f52 870 }
emh203 0:7798270c1f52 871 else
emh203 0:7798270c1f52 872 {
emh203 0:7798270c1f52 873 PC.printf("Bad argument... %s. Should be integer between 0 and 100",arg);
emh203 0:7798270c1f52 874 }
emh203 0:7798270c1f52 875
emh203 0:7798270c1f52 876 }
emh203 0:7798270c1f52 877
emh203 0:7798270c1f52 878
emh203 0:7798270c1f52 879 void TerminalCmd_T(char *arg)
emh203 0:7798270c1f52 880 {
emh203 0:7798270c1f52 881 float Temp = 0;
emh203 0:7798270c1f52 882 int Channel = -1;
emh203 0:7798270c1f52 883
emh203 0:7798270c1f52 884 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 885 {
emh203 0:7798270c1f52 886 Temp = ReadThermocouple(Channel);
emh203 0:7798270c1f52 887 PC.printf("TEMP:%d:%.2f\r\n",Channel,Temp);
emh203 0:7798270c1f52 888 }
emh203 0:7798270c1f52 889 else
emh203 0:7798270c1f52 890 {
emh203 0:7798270c1f52 891 for(Channel = 0; Channel<12;Channel++)
emh203 0:7798270c1f52 892 {
emh203 0:7798270c1f52 893 Temp = ReadThermocouple(Channel);
emh203 0:7798270c1f52 894 PC.printf("TEMP:%d:%.2f\r\n",Channel,Temp);
emh203 0:7798270c1f52 895 }
emh203 0:7798270c1f52 896 }
emh203 0:7798270c1f52 897 }
emh203 0:7798270c1f52 898
emh203 0:7798270c1f52 899 void TerminalCmd_Buzz(char *arg)
emh203 0:7798270c1f52 900 {
emh203 0:7798270c1f52 901
emh203 0:7798270c1f52 902 float T = -1.0;
emh203 0:7798270c1f52 903
emh203 0:7798270c1f52 904 if(sscanf(arg,"%f",&T) == 1)
emh203 0:7798270c1f52 905 {
emh203 0:7798270c1f52 906 if(T>=0.0 && T<=5.0)
emh203 0:7798270c1f52 907 {
emh203 0:7798270c1f52 908 Buzz(T);
emh203 0:7798270c1f52 909 }
emh203 0:7798270c1f52 910 else
emh203 0:7798270c1f52 911 {
emh203 0:7798270c1f52 912 PC.printf("%f is an invalid time period for buzz. Time should be between 0.0 and 5.0 seconds",T);
emh203 0:7798270c1f52 913 }
emh203 0:7798270c1f52 914 }
emh203 0:7798270c1f52 915 else
emh203 0:7798270c1f52 916 {
emh203 0:7798270c1f52 917 PC.printf("Bad argument... %s. Should be float between 0.0 and 5.0",arg);
emh203 0:7798270c1f52 918 }
emh203 0:7798270c1f52 919
emh203 0:7798270c1f52 920 }
emh203 0:7798270c1f52 921
emh203 0:7798270c1f52 922
emh203 0:7798270c1f52 923
emh203 0:7798270c1f52 924
emh203 0:7798270c1f52 925 //*****************************************************************
emh203 0:7798270c1f52 926 //Plumbing.....
emh203 0:7798270c1f52 927 //*****************************************************************
emh203 0:7798270c1f52 928
emh203 0:7798270c1f52 929 #define NUM_TERMINAL_COMMANDS (sizeof(MyTerminalCallbackRecords)/sizeof(TerminalCallbackRecord))
emh203 0:7798270c1f52 930
emh203 0:7798270c1f52 931 char TerminalLineBuf[MAX_TERMINAL_LINE_CHARS];
emh203 0:7798270c1f52 932 uint8_t TerminalPos;
emh203 0:7798270c1f52 933 char TerminalCmdBuf[MAX_TERMINAL_CMD_CHARS+1];
emh203 0:7798270c1f52 934 char TerminalArgs[MAX_TERMINAL_LINE_CHARS-MAX_TERMINAL_CMD_CHARS];
emh203 0:7798270c1f52 935 uint8_t NextCharIn;
emh203 0:7798270c1f52 936 uint8_t CmdFound;
emh203 0:7798270c1f52 937
emh203 0:7798270c1f52 938 void TerminalBootMsg()
emh203 0:7798270c1f52 939 {
emh203 0:7798270c1f52 940
emh203 0:7798270c1f52 941 PC.printf("\r\n\r\n");
emh203 0:7798270c1f52 942 PC.printf("***********************************\r\n");
emh203 0:7798270c1f52 943 PC.printf("CHEM Control Box \r\n");
emh203 0:7798270c1f52 944 PC.printf("API Version %s \r\n",API_VERSION);
emh203 0:7798270c1f52 945 PC.printf("Copyright (C) <2013> Eli Hughes\r\n");
emh203 0:7798270c1f52 946 PC.printf("Wavenumber LLC\r\n");
emh203 0:7798270c1f52 947 PC.printf("***********************************\r\n\r\n>");
emh203 0:7798270c1f52 948
emh203 0:7798270c1f52 949 }
emh203 0:7798270c1f52 950
emh203 0:7798270c1f52 951 void InitTerminal()
emh203 0:7798270c1f52 952 {
emh203 0:7798270c1f52 953
emh203 0:7798270c1f52 954 PC.baud(115200);
emh203 0:7798270c1f52 955 TerminalPos = 0;
emh203 0:7798270c1f52 956 CmdFound = 0;
emh203 0:7798270c1f52 957 TerminalBootMsg();
emh203 0:7798270c1f52 958 }
emh203 0:7798270c1f52 959
emh203 0:7798270c1f52 960 void TerminalCmd_Help(char *arg)
emh203 0:7798270c1f52 961 {
emh203 0:7798270c1f52 962 uint8_t i;
emh203 0:7798270c1f52 963
emh203 0:7798270c1f52 964 PC.printf("\r\n\r\nCommand List:\r\n");
emh203 0:7798270c1f52 965 PC.printf("----------------------\r\n");
emh203 0:7798270c1f52 966
emh203 0:7798270c1f52 967 for(i=0;i<NUM_TERMINAL_COMMANDS;i++)
emh203 0:7798270c1f52 968 {
emh203 0:7798270c1f52 969 PC.printf("%s ----> %s\r\n\r\n",MyTerminalCallbackRecords[i].CommandString,MyTerminalCallbackRecords[i].HelpString);
emh203 0:7798270c1f52 970 }
emh203 0:7798270c1f52 971
emh203 0:7798270c1f52 972 PC.printf("\r\n\r\n");
emh203 0:7798270c1f52 973 }
emh203 0:7798270c1f52 974
emh203 0:7798270c1f52 975 void TerminalCmd_Reboot(char *arg)
emh203 0:7798270c1f52 976 {
emh203 0:7798270c1f52 977 TerminalBootMsg();
emh203 0:7798270c1f52 978 }
emh203 0:7798270c1f52 979
emh203 0:7798270c1f52 980 void ProcessTerminal()
emh203 0:7798270c1f52 981 {
emh203 0:7798270c1f52 982 uint8_t i,j;
emh203 0:7798270c1f52 983 uint8_t ArgsFound;
emh203 0:7798270c1f52 984
emh203 0:7798270c1f52 985 if(PC.readable())
emh203 0:7798270c1f52 986 {
emh203 0:7798270c1f52 987 NextCharIn = PC.getc();
emh203 0:7798270c1f52 988
emh203 0:7798270c1f52 989 switch(NextCharIn)
emh203 0:7798270c1f52 990 {
emh203 0:7798270c1f52 991 case '\r':
emh203 0:7798270c1f52 992
emh203 0:7798270c1f52 993 TerminalLineBuf[TerminalPos++] = 0x0;
emh203 0:7798270c1f52 994 PC.putc(NextCharIn);
emh203 0:7798270c1f52 995
emh203 0:7798270c1f52 996 if(TerminalPos > 1)
emh203 0:7798270c1f52 997 {
emh203 0:7798270c1f52 998 //find the command
emh203 0:7798270c1f52 999 i=0;
emh203 0:7798270c1f52 1000 while(TerminalLineBuf[i]>0x20 && TerminalLineBuf[i]<0x7f)
emh203 0:7798270c1f52 1001 {
emh203 0:7798270c1f52 1002 TerminalCmdBuf[i] = TerminalLineBuf[i];
emh203 0:7798270c1f52 1003 i++;
emh203 0:7798270c1f52 1004
emh203 0:7798270c1f52 1005 if(i==MAX_TERMINAL_CMD_CHARS)
emh203 0:7798270c1f52 1006 {
emh203 0:7798270c1f52 1007 break;
emh203 0:7798270c1f52 1008 }
emh203 0:7798270c1f52 1009 }
emh203 0:7798270c1f52 1010
emh203 0:7798270c1f52 1011 TerminalCmdBuf[i] = 0;
emh203 0:7798270c1f52 1012 TerminalCmdBuf[i+1] = 0;
emh203 0:7798270c1f52 1013
emh203 0:7798270c1f52 1014
emh203 0:7798270c1f52 1015 ArgsFound = TRUE;
emh203 0:7798270c1f52 1016 memset(TerminalArgs,0x00,sizeof(TerminalArgs));
emh203 0:7798270c1f52 1017 //scan for num terminator or next non whitespace
emh203 0:7798270c1f52 1018 while(TerminalLineBuf[i]<=0x20 && (i<MAX_TERMINAL_LINE_CHARS))
emh203 0:7798270c1f52 1019 {
emh203 0:7798270c1f52 1020 if(TerminalLineBuf[i] == 0x00)
emh203 0:7798270c1f52 1021 {
emh203 0:7798270c1f52 1022
emh203 0:7798270c1f52 1023 //if we find a NULL terminator before a non whitespace character they flag for no arguments
emh203 0:7798270c1f52 1024 ArgsFound = FALSE;
emh203 0:7798270c1f52 1025 break;
emh203 0:7798270c1f52 1026 }
emh203 0:7798270c1f52 1027 i++;
emh203 0:7798270c1f52 1028 }
emh203 0:7798270c1f52 1029
emh203 0:7798270c1f52 1030 if(ArgsFound == TRUE)
emh203 0:7798270c1f52 1031 {
emh203 0:7798270c1f52 1032 strcpy(TerminalArgs,&TerminalLineBuf[i]);
emh203 0:7798270c1f52 1033
emh203 0:7798270c1f52 1034 //trim trailing whitespace
emh203 0:7798270c1f52 1035 i = sizeof(TerminalArgs)-1;
emh203 0:7798270c1f52 1036
emh203 0:7798270c1f52 1037 while((TerminalArgs[i]<0x21) && (i>0))
emh203 0:7798270c1f52 1038 {
emh203 0:7798270c1f52 1039 TerminalArgs[i]= 0x00;
emh203 0:7798270c1f52 1040 i--;
emh203 0:7798270c1f52 1041 }
emh203 0:7798270c1f52 1042 }
emh203 0:7798270c1f52 1043
emh203 0:7798270c1f52 1044 CmdFound = FALSE;
emh203 0:7798270c1f52 1045 for(j=0;j<NUM_TERMINAL_COMMANDS;j++)
emh203 0:7798270c1f52 1046 {
emh203 0:7798270c1f52 1047 if(strcmp(TerminalCmdBuf,MyTerminalCallbackRecords[j].CommandString) == 0)
emh203 0:7798270c1f52 1048 {
emh203 0:7798270c1f52 1049 PC.printf("\r\n");
emh203 0:7798270c1f52 1050 if(MyTerminalCallbackRecords[j].Callback != NULL)
emh203 0:7798270c1f52 1051 MyTerminalCallbackRecords[j].Callback(TerminalArgs);
emh203 0:7798270c1f52 1052
emh203 0:7798270c1f52 1053 CmdFound = TRUE;
emh203 0:7798270c1f52 1054 break;
emh203 0:7798270c1f52 1055 }
emh203 0:7798270c1f52 1056 }
emh203 0:7798270c1f52 1057 if(CmdFound == FALSE)
emh203 0:7798270c1f52 1058 {
emh203 0:7798270c1f52 1059 PC.printf("\r\n%s command not recognized.\r\n\r\n",TerminalCmdBuf);
emh203 0:7798270c1f52 1060 TerminalCmd_Help("no arg");
emh203 0:7798270c1f52 1061
emh203 0:7798270c1f52 1062 }
emh203 0:7798270c1f52 1063 }
emh203 0:7798270c1f52 1064 PC.printf("\r\n>");
emh203 0:7798270c1f52 1065 TerminalPos = 0;
emh203 0:7798270c1f52 1066
emh203 0:7798270c1f52 1067 break;
emh203 0:7798270c1f52 1068
emh203 0:7798270c1f52 1069 case '\b':
emh203 0:7798270c1f52 1070 if(TerminalPos > 0)
emh203 0:7798270c1f52 1071 {
emh203 0:7798270c1f52 1072 TerminalPos--;
emh203 0:7798270c1f52 1073 PC.putc(NextCharIn);
emh203 0:7798270c1f52 1074 }
emh203 0:7798270c1f52 1075 break;
emh203 0:7798270c1f52 1076
emh203 0:7798270c1f52 1077 default:
emh203 0:7798270c1f52 1078
emh203 0:7798270c1f52 1079 if(TerminalPos == 0 && NextCharIn == 0x020)
emh203 0:7798270c1f52 1080 {
emh203 0:7798270c1f52 1081 //Do nothing if space bar is pressed at beginning of line
emh203 0:7798270c1f52 1082 }
emh203 0:7798270c1f52 1083 else if(NextCharIn >= 0x20 && NextCharIn<0x7F)
emh203 0:7798270c1f52 1084 {
emh203 0:7798270c1f52 1085
emh203 0:7798270c1f52 1086 if(TerminalPos < MAX_TERMINAL_LINE_CHARS-1)
emh203 0:7798270c1f52 1087 {
emh203 0:7798270c1f52 1088 TerminalLineBuf[TerminalPos++] = NextCharIn;
emh203 0:7798270c1f52 1089 PC.putc(NextCharIn);
emh203 0:7798270c1f52 1090 }
emh203 0:7798270c1f52 1091 }
emh203 0:7798270c1f52 1092
emh203 0:7798270c1f52 1093 break;
emh203 0:7798270c1f52 1094
emh203 0:7798270c1f52 1095 }
emh203 0:7798270c1f52 1096 }
emh203 0:7798270c1f52 1097
emh203 0:7798270c1f52 1098 }
emh203 0:7798270c1f52 1099
emh203 0:7798270c1f52 1100
emh203 0:7798270c1f52 1101
emh203 0:7798270c1f52 1102
emh203 0:7798270c1f52 1103
emh203 0:7798270c1f52 1104 // _ _____ _____ _______ _____ _____ _ _ _____ _____ _____
emh203 0:7798270c1f52 1105 // | | / ____| __ \ / / ____| __ \ /\ | __ \| | | |_ _/ ____|/ ____|
emh203 0:7798270c1f52 1106 // | | | | | | | | / / | __| |__) | / \ | |__) | |__| | | || | | (___
emh203 0:7798270c1f52 1107 // | | | | | | | |/ /| | |_ | _ / / /\ \ | ___/| __ | | || | \___ \
emh203 0:7798270c1f52 1108 // | |___| |____| |__| / / | |__| | | \ \ / ____ \| | | | | |_| || |____ ____) |
emh203 0:7798270c1f52 1109 // |______\_____|_____/_/ \_____|_| \_\/_/ \_\_| |_| |_|_____\_____|_____/
emh203 0:7798270c1f52 1110 //
emh203 0:7798270c1f52 1111 //
emh203 0:7798270c1f52 1112
emh203 0:7798270c1f52 1113 void SmartSwitch_Reset();
emh203 0:7798270c1f52 1114 void SmartSwitch_SetBrightness(uint8_t Brightness);
emh203 0:7798270c1f52 1115 void InitSmartSwitch();
emh203 0:7798270c1f52 1116 void PowerUpSmartSwitch();
emh203 0:7798270c1f52 1117 void PowerDownSmartSwitch();
emh203 0:7798270c1f52 1118 void SmartSwitchWriteByte(uint8_t DataOut);
emh203 0:7798270c1f52 1119 void SmartSwitch_SetBackLightColor2(uint8_t RGB);
emh203 0:7798270c1f52 1120 void SmartSwitch_ImageDump(uint8_t *Img);
emh203 0:7798270c1f52 1121 void SmartSwitchClear();
emh203 0:7798270c1f52 1122
emh203 0:7798270c1f52 1123
emh203 0:7798270c1f52 1124
emh203 0:7798270c1f52 1125
emh203 0:7798270c1f52 1126 #define BACK_BUFFER_SIZE_X (64)
emh203 0:7798270c1f52 1127 #define BACK_BUFFER_SIZE_Y (32)
emh203 0:7798270c1f52 1128
emh203 0:7798270c1f52 1129 #define PHYSICAL_DISPLAY_XRES (uint8_t)(64)
emh203 0:7798270c1f52 1130 #define PHYSICAL_DISPLAY_YRES (uint8_t)(32)
emh203 0:7798270c1f52 1131 #define DISPLAY_X_WIDTH_BYTE (PHYSICAL_DISPLAY_XRES>>3)
emh203 0:7798270c1f52 1132 #define DISPLAY_BUFFER_TOTAL_SIZE (DISPLAY_X_WIDTH_BYTE*PHYSICAL_DISPLAY_YRES*2)
emh203 0:7798270c1f52 1133 #define GREEN_DATA_BUFFER_OFFSET (DISPLAY_X_WIDTH_BYTE * PHYSICAL_DISPLAY_YRES)
emh203 0:7798270c1f52 1134 #define PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES (PHYSICAL_DISPLAY_XRES>>3)
emh203 0:7798270c1f52 1135 #define PHYSICAL_DISPLAY_PLANE_BUFFER_SIZE (PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES * PHYSICAL_DISPLAY_YRES)
emh203 0:7798270c1f52 1136 #define PHYSICAL_DISPLAY_BUFFER_TOTAL_SIZE (PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES * PHYSICAL_DISPLAY_YRES*2)
emh203 0:7798270c1f52 1137
emh203 0:7798270c1f52 1138 #define SMART_SWITCH_CMD_DISPLAY_DATA 0x55
emh203 0:7798270c1f52 1139 #define SMART_SWITCH_CMD_SET_BACKLIGHT_COLOR 0x40
emh203 0:7798270c1f52 1140 #define SMART_SWITCH_CMD_SET_BRIGHTNESS 0x41
emh203 0:7798270c1f52 1141 #define SMART_SWITCH_CMD_RESET 0x5E
emh203 0:7798270c1f52 1142 #define SMART_SWITCH_CMD_RESET_PARAMETER 0x03
emh203 0:7798270c1f52 1143
emh203 0:7798270c1f52 1144 #define SMART_SWITCH_BACKLIGHT_RED (0x03<<4)
emh203 0:7798270c1f52 1145 #define SMART_SWITCH_BACKLIGHT_YELLOW (0x03<<4)|(0x03<<2)
emh203 0:7798270c1f52 1146 #define SMART_SWITCH_BACKLIGHT_GREEN (0x03<<2)
emh203 0:7798270c1f52 1147
emh203 0:7798270c1f52 1148 #define GFX_MAX_STRING_LEN 32
emh203 0:7798270c1f52 1149
emh203 0:7798270c1f52 1150 void SmartSwitch_ImageDump(uint8_t *Img)
emh203 0:7798270c1f52 1151 {
emh203 0:7798270c1f52 1152 int i;
emh203 0:7798270c1f52 1153
emh203 0:7798270c1f52 1154 SPI1.format(8,2);
emh203 0:7798270c1f52 1155
emh203 0:7798270c1f52 1156 SmartSwitch_SS = 0;
emh203 0:7798270c1f52 1157 SmartSwitchWriteByte(SMART_SWITCH_CMD_DISPLAY_DATA);
emh203 0:7798270c1f52 1158
emh203 0:7798270c1f52 1159 for(i=0;i<256;i++)
emh203 0:7798270c1f52 1160 {
emh203 0:7798270c1f52 1161 SmartSwitchWriteByte(Img[i]);
emh203 0:7798270c1f52 1162 }
emh203 0:7798270c1f52 1163
emh203 0:7798270c1f52 1164 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 1165 }
emh203 0:7798270c1f52 1166
emh203 0:7798270c1f52 1167 void SmartSwitchClear()
emh203 0:7798270c1f52 1168 {
emh203 0:7798270c1f52 1169 int i;
emh203 0:7798270c1f52 1170
emh203 0:7798270c1f52 1171
emh203 0:7798270c1f52 1172 SPI1.format(8,2);
emh203 0:7798270c1f52 1173
emh203 0:7798270c1f52 1174 SmartSwitch_SS = 0;
emh203 0:7798270c1f52 1175 SmartSwitchWriteByte(SMART_SWITCH_CMD_DISPLAY_DATA);
emh203 0:7798270c1f52 1176
emh203 0:7798270c1f52 1177 for(i=0;i<256;i++)
emh203 0:7798270c1f52 1178 {
emh203 0:7798270c1f52 1179 SmartSwitchWriteByte(0x00);
emh203 0:7798270c1f52 1180 }
emh203 0:7798270c1f52 1181
emh203 0:7798270c1f52 1182 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 1183 }
emh203 0:7798270c1f52 1184
emh203 0:7798270c1f52 1185 void SmartSwitch_Reset()
emh203 0:7798270c1f52 1186 {
emh203 0:7798270c1f52 1187
emh203 0:7798270c1f52 1188 SPI1.format(8,2);
emh203 0:7798270c1f52 1189
emh203 0:7798270c1f52 1190 SmartSwitch_SS = 0;
emh203 0:7798270c1f52 1191 SmartSwitchWriteByte(SMART_SWITCH_CMD_RESET);
emh203 0:7798270c1f52 1192 SmartSwitchWriteByte(SMART_SWITCH_CMD_RESET_PARAMETER);
emh203 0:7798270c1f52 1193 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 1194 }
emh203 0:7798270c1f52 1195
emh203 0:7798270c1f52 1196 void SmartSwitch_SetBackLightColor(uint8_t Red,uint8_t Green,uint8_t Blue)
emh203 0:7798270c1f52 1197 {
emh203 0:7798270c1f52 1198
emh203 0:7798270c1f52 1199 SPI1.format(8,2);
emh203 0:7798270c1f52 1200
emh203 0:7798270c1f52 1201 SmartSwitch_SS = 0;
emh203 0:7798270c1f52 1202 SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BACKLIGHT_COLOR);
emh203 0:7798270c1f52 1203 SmartSwitchWriteByte(Red<<6 | Green<<4 | Blue <<2 | 0x3);
emh203 0:7798270c1f52 1204 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 1205 }
emh203 0:7798270c1f52 1206
emh203 0:7798270c1f52 1207 void SmartSwitch_SetBackLightColor2(uint8_t RGB)
emh203 0:7798270c1f52 1208 {
emh203 0:7798270c1f52 1209 SPI1.format(8,2);
emh203 0:7798270c1f52 1210
emh203 0:7798270c1f52 1211 SmartSwitch_SS = 0;
emh203 0:7798270c1f52 1212 SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BACKLIGHT_COLOR);
emh203 0:7798270c1f52 1213 SmartSwitchWriteByte(RGB<<2 | 0x3);
emh203 0:7798270c1f52 1214 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 1215 }
emh203 0:7798270c1f52 1216
emh203 0:7798270c1f52 1217 void SmartSwitch_SetBrightness(uint8_t Brightness)
emh203 0:7798270c1f52 1218 {
emh203 0:7798270c1f52 1219 SPI1.format(8,2);
emh203 0:7798270c1f52 1220
emh203 0:7798270c1f52 1221 SmartSwitch_SS = 0;
emh203 0:7798270c1f52 1222 SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BRIGHTNESS);
emh203 0:7798270c1f52 1223 SmartSwitchWriteByte(Brightness<<5 | 0x1F);
emh203 0:7798270c1f52 1224 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 1225 }
emh203 0:7798270c1f52 1226
emh203 0:7798270c1f52 1227 void InitSmartSwitch()
emh203 0:7798270c1f52 1228 {
emh203 0:7798270c1f52 1229 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 1230 SmartSwitch_Reset();
emh203 0:7798270c1f52 1231 }
emh203 0:7798270c1f52 1232
emh203 0:7798270c1f52 1233 void SmartSwitchWriteByte(uint8_t DataOut)
emh203 0:7798270c1f52 1234 {
emh203 0:7798270c1f52 1235
emh203 0:7798270c1f52 1236 SPI1.write(DataOut);
emh203 0:7798270c1f52 1237
emh203 0:7798270c1f52 1238 }
emh203 0:7798270c1f52 1239
emh203 0:7798270c1f52 1240
emh203 0:7798270c1f52 1241 //Linking Functions to Physical Screen
emh203 0:7798270c1f52 1242 //***********************************************************************************
emh203 0:7798270c1f52 1243
emh203 0:7798270c1f52 1244 void GFX_InitPhysicalScreen()
emh203 0:7798270c1f52 1245 {
emh203 0:7798270c1f52 1246 InitSmartSwitch();
emh203 0:7798270c1f52 1247 }
emh203 0:7798270c1f52 1248
emh203 0:7798270c1f52 1249
emh203 0:7798270c1f52 1250 const uint8_t BitReverseTable[256] =
emh203 0:7798270c1f52 1251 {
emh203 0:7798270c1f52 1252 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
emh203 0:7798270c1f52 1253 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
emh203 0:7798270c1f52 1254 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
emh203 0:7798270c1f52 1255 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
emh203 0:7798270c1f52 1256 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
emh203 0:7798270c1f52 1257 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
emh203 0:7798270c1f52 1258 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
emh203 0:7798270c1f52 1259 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
emh203 0:7798270c1f52 1260 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
emh203 0:7798270c1f52 1261 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
emh203 0:7798270c1f52 1262 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
emh203 0:7798270c1f52 1263 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
emh203 0:7798270c1f52 1264 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
emh203 0:7798270c1f52 1265 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
emh203 0:7798270c1f52 1266 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
emh203 0:7798270c1f52 1267 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
emh203 0:7798270c1f52 1268 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
emh203 0:7798270c1f52 1269 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
emh203 0:7798270c1f52 1270 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
emh203 0:7798270c1f52 1271 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
emh203 0:7798270c1f52 1272 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
emh203 0:7798270c1f52 1273 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
emh203 0:7798270c1f52 1274 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
emh203 0:7798270c1f52 1275 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
emh203 0:7798270c1f52 1276 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
emh203 0:7798270c1f52 1277 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
emh203 0:7798270c1f52 1278 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
emh203 0:7798270c1f52 1279 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
emh203 0:7798270c1f52 1280 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
emh203 0:7798270c1f52 1281 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
emh203 0:7798270c1f52 1282 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
emh203 0:7798270c1f52 1283 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
emh203 0:7798270c1f52 1284 };
emh203 0:7798270c1f52 1285
emh203 0:7798270c1f52 1286 void GFX_DumpRenderContextToPhysicalScreen(RenderContext *Image)
emh203 0:7798270c1f52 1287 {
emh203 0:7798270c1f52 1288 int x,y;
emh203 0:7798270c1f52 1289 uint8_t NextByteOut;
emh203 0:7798270c1f52 1290
emh203 0:7798270c1f52 1291 SPI1.format(8,2);
emh203 0:7798270c1f52 1292
emh203 0:7798270c1f52 1293 SmartSwitch_SS = 0;
emh203 0:7798270c1f52 1294 SmartSwitchWriteByte(SMART_SWITCH_CMD_DISPLAY_DATA);
emh203 0:7798270c1f52 1295
emh203 0:7798270c1f52 1296 for(y=0;y<PHYSICAL_DISPLAY_YRES;y++)
emh203 0:7798270c1f52 1297 {
emh203 0:7798270c1f52 1298 for(x=0;x<PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES;x++)
emh203 0:7798270c1f52 1299 {
emh203 0:7798270c1f52 1300 //Need to rotate the display 180 degrees
emh203 0:7798270c1f52 1301 NextByteOut = Image->RenderPlane.BitPlaneSpace[(((PHYSICAL_DISPLAY_YRES - y - 1) * PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES)) + x];
emh203 0:7798270c1f52 1302 SmartSwitchWriteByte(BitReverseTable[NextByteOut]);
emh203 0:7798270c1f52 1303 }
emh203 0:7798270c1f52 1304 }
emh203 0:7798270c1f52 1305 SmartSwitch_SS = 1;
emh203 0:7798270c1f52 1306 }
emh203 0:7798270c1f52 1307
emh203 0:7798270c1f52 1308
emh203 0:7798270c1f52 1309 //Device Independent Functions
emh203 0:7798270c1f52 1310 //***********************************************************************************
emh203 0:7798270c1f52 1311
emh203 0:7798270c1f52 1312 //Reserve Space for the backbuffer
emh203 0:7798270c1f52 1313
emh203 0:7798270c1f52 1314 RenderContext BackBuffer;
emh203 0:7798270c1f52 1315 uint8_t BackBufferRenderPlaneSpace[PHYSICAL_DISPLAY_PLANE_BUFFER_SIZE];
emh203 0:7798270c1f52 1316
emh203 0:7798270c1f52 1317 int16_t GFX_Drawcharacter(RenderContext *Image, uint8_t character, int16_t StartX, int16_t StartY, GFXFont *MyFont);
emh203 0:7798270c1f52 1318 int16_t GFX_GetStringWidth(char * String,GFXFont * MyFont);
emh203 0:7798270c1f52 1319
emh203 0:7798270c1f52 1320 //FontData
emh203 0:7798270c1f52 1321
emh203 0:7798270c1f52 1322 #define FONT5x7_FONT_WIDTH 5
emh203 0:7798270c1f52 1323 #define FONT5x7_FONT_HEIGHT 8
emh203 0:7798270c1f52 1324 #define FONT5x7_FONT_ELEMENTS 128
emh203 0:7798270c1f52 1325 #define FONT5x7_FONT_COLUMN_SIZE_IN_BYTE 1
emh203 0:7798270c1f52 1326
emh203 0:7798270c1f52 1327 uint8_t FontTable_Font5x7 [640] = {
emh203 0:7798270c1f52 1328 0x00 ,0x08 ,0x0C ,0xFA ,0x81 ,0xFA ,0x0C ,0x08 ,0x00 ,0x00 ,0x00 ,0x10 ,0x30 ,0x5F ,0x81 ,0x5F ,
emh203 0:7798270c1f52 1329 0x30 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1330 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1331 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1332 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1333 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1334 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1335 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1336 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1337 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1338 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xBE ,0x00 ,0x00 ,0x00 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x00 ,0x28 ,
emh203 0:7798270c1f52 1339 0xFE ,0x28 ,0xFE ,0x28 ,0x48 ,0xFE ,0x54 ,0xFE ,0x24 ,0x06 ,0xE6 ,0x10 ,0xCE ,0xC0 ,0x60 ,0x92 ,
emh203 0:7798270c1f52 1340 0x94 ,0x78 ,0x10 ,0x06 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7C ,0x82 ,0x00 ,0x00 ,0x00 ,0x82 ,0x7C ,0x00 ,
emh203 0:7798270c1f52 1341 0x00 ,0x00 ,0x54 ,0x38 ,0xFE ,0x38 ,0x54 ,0x10 ,0x10 ,0x7C ,0x10 ,0x10 ,0x80 ,0x60 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1342 0x00 ,0x10 ,0x10 ,0x10 ,0x10 ,0x10 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0xC0 ,0x30 ,0x0C ,0x02 ,0x00 ,
emh203 0:7798270c1f52 1343 0x7C ,0xA2 ,0x92 ,0x8A ,0x7C ,0x88 ,0x84 ,0xFE ,0x80 ,0x80 ,0x84 ,0xC2 ,0xA2 ,0x92 ,0x8C ,0x44 ,
emh203 0:7798270c1f52 1344 0x92 ,0x92 ,0x92 ,0x6C ,0x10 ,0x18 ,0x14 ,0xFE ,0x10 ,0x4E ,0x8A ,0x8A ,0x8A ,0x72 ,0x7C ,0x92 ,
emh203 0:7798270c1f52 1345 0x92 ,0x92 ,0x64 ,0x02 ,0xC2 ,0x22 ,0x12 ,0x0E ,0x6C ,0x92 ,0x92 ,0x92 ,0x6C ,0x0C ,0x92 ,0x92 ,
emh203 0:7798270c1f52 1346 0x92 ,0x7C ,0x48 ,0x00 ,0x00 ,0x00 ,0x00 ,0x80 ,0x68 ,0x00 ,0x00 ,0x00 ,0x10 ,0x28 ,0x44 ,0x82 ,
emh203 0:7798270c1f52 1347 0x00 ,0x28 ,0x28 ,0x28 ,0x28 ,0x00 ,0x82 ,0x44 ,0x28 ,0x10 ,0x00 ,0x04 ,0x02 ,0xA2 ,0x12 ,0x0C ,
emh203 0:7798270c1f52 1348 0x3C ,0x42 ,0x9A ,0xA2 ,0x1C ,0xF8 ,0x14 ,0x12 ,0x14 ,0xF8 ,0xFE ,0x92 ,0x92 ,0x92 ,0x6C ,0x7C ,
emh203 0:7798270c1f52 1349 0x82 ,0x82 ,0x82 ,0x44 ,0xFE ,0x82 ,0x82 ,0x44 ,0x38 ,0xFE ,0x92 ,0x92 ,0x82 ,0x82 ,0xFE ,0x12 ,
emh203 0:7798270c1f52 1350 0x12 ,0x02 ,0x02 ,0x7C ,0x92 ,0x92 ,0x92 ,0x74 ,0xFE ,0x10 ,0x10 ,0x10 ,0xFE ,0x82 ,0x82 ,0xFE ,
emh203 0:7798270c1f52 1351 0x82 ,0x82 ,0x40 ,0x80 ,0x80 ,0x80 ,0x7E ,0xFE ,0x10 ,0x28 ,0x44 ,0x82 ,0xFE ,0x80 ,0x80 ,0x80 ,
emh203 0:7798270c1f52 1352 0x00 ,0xFE ,0x04 ,0x08 ,0x04 ,0xFE ,0xFE ,0x04 ,0x18 ,0x20 ,0xFE ,0x7C ,0x82 ,0x82 ,0x82 ,0x7C ,
emh203 0:7798270c1f52 1353 0xFE ,0x12 ,0x12 ,0x12 ,0x0C ,0x7C ,0x82 ,0xA2 ,0xC2 ,0xFC ,0xFE ,0x12 ,0x32 ,0x52 ,0x8C ,0x4C ,
emh203 0:7798270c1f52 1354 0x92 ,0x92 ,0x92 ,0x64 ,0x02 ,0x02 ,0xFE ,0x02 ,0x02 ,0x7E ,0x80 ,0x80 ,0x80 ,0x7E ,0x3E ,0x40 ,
emh203 0:7798270c1f52 1355 0x80 ,0x40 ,0x3E ,0xFE ,0x40 ,0x20 ,0x40 ,0xFE ,0xC6 ,0x28 ,0x10 ,0x28 ,0xC6 ,0x02 ,0x04 ,0xF8 ,
emh203 0:7798270c1f52 1356 0x04 ,0x02 ,0xC2 ,0xA2 ,0x92 ,0x8A ,0x86 ,0xFE ,0x82 ,0x82 ,0x00 ,0x00 ,0x02 ,0x0C ,0x30 ,0xC0 ,
emh203 0:7798270c1f52 1357 0x00 ,0x82 ,0x82 ,0xFE ,0x00 ,0x00 ,0x04 ,0x02 ,0x04 ,0x00 ,0x00 ,0x80 ,0x80 ,0x80 ,0x80 ,0x80 ,
emh203 0:7798270c1f52 1358 0x06 ,0x08 ,0x00 ,0x00 ,0x00 ,0x70 ,0x88 ,0x88 ,0x70 ,0x80 ,0xFC ,0x90 ,0x90 ,0x60 ,0x00 ,0x70 ,
emh203 0:7798270c1f52 1359 0x88 ,0x88 ,0x88 ,0x00 ,0x60 ,0x90 ,0x90 ,0x7C ,0x80 ,0x70 ,0xA8 ,0xA8 ,0x90 ,0x00 ,0x10 ,0xF8 ,
emh203 0:7798270c1f52 1360 0x14 ,0x04 ,0x00 ,0x98 ,0xA4 ,0xA4 ,0x78 ,0x00 ,0xFC ,0x20 ,0x10 ,0xE0 ,0x00 ,0xE8 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1361 0x00 ,0x00 ,0x40 ,0x80 ,0x80 ,0x74 ,0x00 ,0xFC ,0x20 ,0x50 ,0x88 ,0x00 ,0xFC ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1362 0x00 ,0xF0 ,0x08 ,0x30 ,0x08 ,0xF0 ,0xF8 ,0x08 ,0x08 ,0xF0 ,0x00 ,0x70 ,0x88 ,0x88 ,0x70 ,0x00 ,
emh203 0:7798270c1f52 1363 0xF8 ,0x24 ,0x24 ,0x18 ,0x00 ,0x18 ,0x24 ,0x24 ,0xF8 ,0x00 ,0xF0 ,0x08 ,0x08 ,0x10 ,0x00 ,0x90 ,
emh203 0:7798270c1f52 1364 0xA8 ,0xA8 ,0x48 ,0x00 ,0x08 ,0x7C ,0x88 ,0x00 ,0x00 ,0x78 ,0x80 ,0x80 ,0x78 ,0x00 ,0x38 ,0x40 ,
emh203 0:7798270c1f52 1365 0x80 ,0x40 ,0x38 ,0x78 ,0x80 ,0x40 ,0x80 ,0x78 ,0x88 ,0x50 ,0x20 ,0x50 ,0x88 ,0x08 ,0x10 ,0xE0 ,
emh203 0:7798270c1f52 1366 0x10 ,0x08 ,0xC8 ,0xA8 ,0x98 ,0x00 ,0x00 ,0x10 ,0x6C ,0x82 ,0x00 ,0x00 ,0xFE ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1367 0x00 ,0x82 ,0x6C ,0x10 ,0x00 ,0x00 ,0x08 ,0x04 ,0x08 ,0x10 ,0x08 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 };
emh203 0:7798270c1f52 1368
emh203 0:7798270c1f52 1369 uint8_t CharacterWidthTable_Font5x7 [128] = {
emh203 0:7798270c1f52 1370 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,
emh203 0:7798270c1f52 1371 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,
emh203 0:7798270c1f52 1372 0x05 ,0x01 ,0x03 ,0x05 ,0x05 ,0x05 ,0x05 ,0x01 ,0x02 ,0x02 ,0x05 ,0x05 ,0x02 ,0x05 ,0x01 ,0x04 ,
emh203 0:7798270c1f52 1373 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x01 ,0x01 ,0x04 ,0x04 ,0x04 ,0x05 ,
emh203 0:7798270c1f52 1374 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x04 ,0x05 ,0x05 ,0x05 ,
emh203 0:7798270c1f52 1375 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x03 ,0x04 ,0x05 ,0x03 ,0x05 ,
emh203 0:7798270c1f52 1376 0x02 ,0x05 ,0x04 ,0x04 ,0x05 ,0x04 ,0x04 ,0x04 ,0x04 ,0x01 ,0x04 ,0x04 ,0x01 ,0x05 ,0x04 ,0x05 ,
emh203 0:7798270c1f52 1377 0x05 ,0x05 ,0x04 ,0x04 ,0x03 ,0x04 ,0x05 ,0x05 ,0x05 ,0x05 ,0x03 ,0x03 ,0x01 ,0x05 ,0x05 ,0x05 };
emh203 0:7798270c1f52 1378
emh203 0:7798270c1f52 1379 #define FONT3x5_FONT_WIDTH 3
emh203 0:7798270c1f52 1380 #define FONT3x5_FONT_HEIGHT 5
emh203 0:7798270c1f52 1381 #define FONT3x5_ELEMENTS 128
emh203 0:7798270c1f52 1382 #define FONT3x5_FONT_COLUMN_SIZE_IN_BYTE 1
emh203 0:7798270c1f52 1383
emh203 0:7798270c1f52 1384
emh203 0:7798270c1f52 1385 uint8_t FontTable_Font3x5 [384] = {
emh203 0:7798270c1f52 1386 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1387 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1388 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1389 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1390 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1391 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
emh203 0:7798270c1f52 1392 0x00 ,0x00 ,0x00 ,0x17 ,0x00 ,0x00 ,0x03 ,0x00 ,0x03 ,0x0E ,0x1F ,0x0E ,0x14 ,0x1F ,0x0A ,0x00 ,
emh203 0:7798270c1f52 1393 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x00 ,0x00 ,0x0E ,0x11 ,0x00 ,0x11 ,0x0E ,0x00 ,0x15 ,0x0E ,
emh203 0:7798270c1f52 1394 0x15 ,0x04 ,0x0E ,0x04 ,0x10 ,0x08 ,0x00 ,0x04 ,0x04 ,0x04 ,0x10 ,0x00 ,0x00 ,0x18 ,0x04 ,0x03 ,
emh203 0:7798270c1f52 1395 0x0E ,0x11 ,0x0E ,0x12 ,0x1F ,0x10 ,0x19 ,0x15 ,0x16 ,0x11 ,0x15 ,0x0A ,0x07 ,0x04 ,0x1F ,0x17 ,
emh203 0:7798270c1f52 1396 0x15 ,0x09 ,0x1E ,0x15 ,0x18 ,0x01 ,0x1D ,0x03 ,0x1B ,0x15 ,0x1B ,0x06 ,0x15 ,0x0E ,0x0A ,0x00 ,
emh203 0:7798270c1f52 1397 0x00 ,0x10 ,0x0A ,0x00 ,0x04 ,0x0A ,0x11 ,0x00 ,0x00 ,0x00 ,0x11 ,0x0A ,0x04 ,0x01 ,0x15 ,0x02 ,
emh203 0:7798270c1f52 1398 0x09 ,0x15 ,0x0E ,0x1E ,0x05 ,0x1E ,0x1F ,0x15 ,0x0A ,0x0E ,0x11 ,0x0A ,0x1F ,0x11 ,0x0E ,0x1F ,
emh203 0:7798270c1f52 1399 0x15 ,0x11 ,0x1F ,0x05 ,0x05 ,0x1E ,0x15 ,0x1D ,0x1F ,0x04 ,0x1F ,0x11 ,0x1F ,0x11 ,0x08 ,0x10 ,
emh203 0:7798270c1f52 1400 0x0F ,0x1F ,0x06 ,0x19 ,0x1F ,0x10 ,0x10 ,0x1F ,0x02 ,0x1F ,0x1F ,0x06 ,0x1F ,0x1F ,0x11 ,0x1F ,
emh203 0:7798270c1f52 1401 0x1F ,0x05 ,0x07 ,0x1F ,0x19 ,0x1F ,0x1F ,0x0D ,0x16 ,0x16 ,0x15 ,0x1D ,0x01 ,0x1F ,0x01 ,0x1F ,
emh203 0:7798270c1f52 1402 0x10 ,0x1F ,0x0F ,0x10 ,0x0F ,0x1F ,0x08 ,0x1F ,0x1B ,0x04 ,0x1B ,0x01 ,0x1E ,0x01 ,0x19 ,0x15 ,
emh203 0:7798270c1f52 1403 0x13 ,0x1F ,0x11 ,0x00 ,0x03 ,0x0C ,0x10 ,0x11 ,0x1F ,0x00 ,0x02 ,0x01 ,0x02 ,0x10 ,0x10 ,0x10 ,
emh203 0:7798270c1f52 1404 0x01 ,0x02 ,0x00 ,0x08 ,0x14 ,0x1C ,0x1F ,0x14 ,0x08 ,0x0C ,0x12 ,0x12 ,0x08 ,0x14 ,0x1F ,0x0C ,
emh203 0:7798270c1f52 1405 0x16 ,0x16 ,0x14 ,0x0E ,0x05 ,0x06 ,0x15 ,0x0F ,0x1F ,0x04 ,0x18 ,0x1D ,0x00 ,0x00 ,0x10 ,0x0D ,
emh203 0:7798270c1f52 1406 0x00 ,0x1F ,0x0C ,0x12 ,0x1F ,0x00 ,0x00 ,0x1C ,0x08 ,0x1C ,0x1C ,0x02 ,0x1C ,0x0C ,0x12 ,0x0C ,
emh203 0:7798270c1f52 1407 0x1E ,0x05 ,0x02 ,0x02 ,0x05 ,0x1E ,0x1C ,0x02 ,0x04 ,0x14 ,0x1A ,0x00 ,0x04 ,0x1E ,0x04 ,0x1E ,
emh203 0:7798270c1f52 1408 0x10 ,0x1E ,0x0E ,0x10 ,0x0E ,0x1C ,0x08 ,0x1C ,0x12 ,0x0C ,0x12 ,0x12 ,0x0C ,0x02 ,0x12 ,0x1A ,
emh203 0:7798270c1f52 1409 0x16 ,0x04 ,0x0E ,0x11 ,0x1F ,0x00 ,0x00 ,0x11 ,0x0E ,0x04 ,0x02 ,0x02 ,0x04 ,0x00 ,0x00 ,0x00 };
emh203 0:7798270c1f52 1410
emh203 0:7798270c1f52 1411
emh203 0:7798270c1f52 1412 uint8_t CharacterWidthTable_Font3x5 [128] = {
emh203 0:7798270c1f52 1413 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,
emh203 0:7798270c1f52 1414 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,
emh203 0:7798270c1f52 1415 0x03 ,0x01 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x01 ,0x02 ,0x03 ,0x03 ,0x03 ,0x02 ,0x03 ,0x01 ,0x03 ,
emh203 0:7798270c1f52 1416 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x01 ,0x02 ,0x03 ,0x03 ,0x03 ,0x03 ,
emh203 0:7798270c1f52 1417 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,
emh203 0:7798270c1f52 1418 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x02 ,0x03 ,0x02 ,0x03 ,0x03 ,
emh203 0:7798270c1f52 1419 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x01 ,0x03 ,0x03 ,0x01 ,0x03 ,0x03 ,0x03 ,
emh203 0:7798270c1f52 1420 0x03 ,0x03 ,0x03 ,0x02 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x01 ,0x03 ,0x03 ,0x03 };
emh203 0:7798270c1f52 1421
emh203 0:7798270c1f52 1422 GFXFont Font5x7;
emh203 0:7798270c1f52 1423 GFXFont Font3x5;
emh203 0:7798270c1f52 1424
emh203 0:7798270c1f52 1425 void GFX_Init()
emh203 0:7798270c1f52 1426 {
emh203 0:7798270c1f52 1427
emh203 0:7798270c1f52 1428 //Staticially Allocate and setup the backbuffer space;
emh203 0:7798270c1f52 1429
emh203 0:7798270c1f52 1430 BackBuffer.RenderPlane.BitPlaneSpace = &BackBufferRenderPlaneSpace[0];
emh203 0:7798270c1f52 1431
emh203 0:7798270c1f52 1432 BackBuffer.SizeX = BACK_BUFFER_SIZE_X;
emh203 0:7798270c1f52 1433 BackBuffer.SizeY = BACK_BUFFER_SIZE_Y;
emh203 0:7798270c1f52 1434
emh203 0:7798270c1f52 1435 BackBuffer.RenderPlane.SizeX = BACK_BUFFER_SIZE_X;
emh203 0:7798270c1f52 1436 BackBuffer.RenderPlane.SizeY = BACK_BUFFER_SIZE_Y;
emh203 0:7798270c1f52 1437
emh203 0:7798270c1f52 1438
emh203 0:7798270c1f52 1439 GFX_FullDisplayBufferClear(&BackBuffer);
emh203 0:7798270c1f52 1440
emh203 0:7798270c1f52 1441 //Initialize the stock fonts
emh203 0:7798270c1f52 1442
emh203 0:7798270c1f52 1443 Font5x7.CharacterWidthTable = (uint8_t *)CharacterWidthTable_Font5x7;
emh203 0:7798270c1f52 1444 Font5x7.FontBuffer = (uint8_t *)FontTable_Font5x7;
emh203 0:7798270c1f52 1445 Font5x7.FontHeight = FONT5x7_FONT_HEIGHT;
emh203 0:7798270c1f52 1446 Font5x7.FontWidth = FONT5x7_FONT_WIDTH;
emh203 0:7798270c1f52 1447 Font5x7.BytesPerColumn = FONT5x7_FONT_COLUMN_SIZE_IN_BYTE;
emh203 0:7798270c1f52 1448
emh203 0:7798270c1f52 1449 Font3x5.CharacterWidthTable = (uint8_t *)CharacterWidthTable_Font3x5;
emh203 0:7798270c1f52 1450 Font3x5.FontBuffer = (uint8_t *)FontTable_Font3x5;
emh203 0:7798270c1f52 1451 Font3x5.FontHeight = FONT3x5_FONT_HEIGHT;
emh203 0:7798270c1f52 1452 Font3x5.FontWidth = FONT3x5_FONT_WIDTH;
emh203 0:7798270c1f52 1453 Font3x5.BytesPerColumn = FONT3x5_FONT_COLUMN_SIZE_IN_BYTE;
emh203 0:7798270c1f52 1454
emh203 0:7798270c1f52 1455 GFX_InitPhysicalScreen();
emh203 0:7798270c1f52 1456
emh203 0:7798270c1f52 1457 }
emh203 0:7798270c1f52 1458
emh203 0:7798270c1f52 1459
emh203 0:7798270c1f52 1460
emh203 0:7798270c1f52 1461 void GFX_FullDisplayBufferClear(RenderContext *Image)
emh203 0:7798270c1f52 1462 {
emh203 0:7798270c1f52 1463 BitPlane_Clear(&Image->RenderPlane);
emh203 0:7798270c1f52 1464 }
emh203 0:7798270c1f52 1465
emh203 0:7798270c1f52 1466
emh203 0:7798270c1f52 1467 void GFX_PutPixel(RenderContext *Image, int16_t x, int16_t y)
emh203 0:7798270c1f52 1468 {
emh203 0:7798270c1f52 1469 if((x<Image->SizeX) && (y<Image->SizeY) && (x>=0) && (y>=0))
emh203 0:7798270c1f52 1470 {
emh203 0:7798270c1f52 1471 BitPlane_Put(&Image->RenderPlane,Image->SizeX-x-1,Image->SizeY-y-1,TRUE);
emh203 0:7798270c1f52 1472 }
emh203 0:7798270c1f52 1473 }
emh203 0:7798270c1f52 1474
emh203 0:7798270c1f52 1475
emh203 0:7798270c1f52 1476
emh203 0:7798270c1f52 1477 #ifndef _INLINE_GFX_GET_PIXEL
emh203 0:7798270c1f52 1478 uint8_t GFX_GetPixel(RenderContext *Image, int16_t x, int16_t y)
emh203 0:7798270c1f52 1479 {
emh203 0:7798270c1f52 1480 uint8_t PixelColor = 0;
emh203 0:7798270c1f52 1481
emh203 0:7798270c1f52 1482 if((x<Image->SizeX) && (y<Image->SizeY) && (x>=0) && (y>=0))
emh203 0:7798270c1f52 1483 {
emh203 0:7798270c1f52 1484
emh203 0:7798270c1f52 1485 PixelColor = BitPlane_Get(&Image->RenderPlane,x,y);
emh203 0:7798270c1f52 1486 }
emh203 0:7798270c1f52 1487
emh203 0:7798270c1f52 1488 return PixelColor;
emh203 0:7798270c1f52 1489 }
emh203 0:7798270c1f52 1490 #endif
emh203 0:7798270c1f52 1491
emh203 0:7798270c1f52 1492
emh203 0:7798270c1f52 1493 void GFX_DrawHline(RenderContext *Image, int16_t XStart, int16_t XStop, int16_t Y)
emh203 0:7798270c1f52 1494 {
emh203 0:7798270c1f52 1495 int16_t LineStart;
emh203 0:7798270c1f52 1496 int16_t LineStop;
emh203 0:7798270c1f52 1497 uint16_t i;
emh203 0:7798270c1f52 1498
emh203 0:7798270c1f52 1499 if((Y<Image->SizeY) && (Y>=0))
emh203 0:7798270c1f52 1500 {
emh203 0:7798270c1f52 1501 if(XStart>XStop)
emh203 0:7798270c1f52 1502 {
emh203 0:7798270c1f52 1503 LineStart = XStop;
emh203 0:7798270c1f52 1504 LineStop = XStart;
emh203 0:7798270c1f52 1505 }
emh203 0:7798270c1f52 1506 else
emh203 0:7798270c1f52 1507 {
emh203 0:7798270c1f52 1508 LineStart = XStart;
emh203 0:7798270c1f52 1509 LineStop = XStop;
emh203 0:7798270c1f52 1510 }
emh203 0:7798270c1f52 1511
emh203 0:7798270c1f52 1512 if(LineStart<0)
emh203 0:7798270c1f52 1513 {
emh203 0:7798270c1f52 1514 LineStart = 0;
emh203 0:7798270c1f52 1515 }
emh203 0:7798270c1f52 1516
emh203 0:7798270c1f52 1517 if(LineStop>Image->SizeX)
emh203 0:7798270c1f52 1518 {
emh203 0:7798270c1f52 1519 LineStop = Image->SizeX-1;
emh203 0:7798270c1f52 1520 }
emh203 0:7798270c1f52 1521
emh203 0:7798270c1f52 1522 if(LineStart == LineStop)
emh203 0:7798270c1f52 1523 {
emh203 0:7798270c1f52 1524 GFX_PutPixel(Image,LineStart,Y);
emh203 0:7798270c1f52 1525 }
emh203 0:7798270c1f52 1526 else
emh203 0:7798270c1f52 1527 {
emh203 0:7798270c1f52 1528 for(i=LineStart; i<=LineStop ; i++)
emh203 0:7798270c1f52 1529 {
emh203 0:7798270c1f52 1530 GFX_PutPixel(Image,i,Y);
emh203 0:7798270c1f52 1531 }
emh203 0:7798270c1f52 1532 }
emh203 0:7798270c1f52 1533 }
emh203 0:7798270c1f52 1534
emh203 0:7798270c1f52 1535 }
emh203 0:7798270c1f52 1536
emh203 0:7798270c1f52 1537
emh203 0:7798270c1f52 1538
emh203 0:7798270c1f52 1539 void GFX_DrawVline(RenderContext *Image, int16_t YStart, int16_t YStop, int16_t X)
emh203 0:7798270c1f52 1540 {
emh203 0:7798270c1f52 1541 int16_t LineStart;
emh203 0:7798270c1f52 1542 int16_t LineStop;
emh203 0:7798270c1f52 1543 int16_t i;
emh203 0:7798270c1f52 1544
emh203 0:7798270c1f52 1545 if((X<Image->SizeX) && (X>=0))
emh203 0:7798270c1f52 1546 {
emh203 0:7798270c1f52 1547
emh203 0:7798270c1f52 1548 if(YStart>YStop)
emh203 0:7798270c1f52 1549 {
emh203 0:7798270c1f52 1550 LineStart = YStop;
emh203 0:7798270c1f52 1551 LineStop = YStart;
emh203 0:7798270c1f52 1552 }
emh203 0:7798270c1f52 1553 else
emh203 0:7798270c1f52 1554 {
emh203 0:7798270c1f52 1555 LineStart = YStart;
emh203 0:7798270c1f52 1556 LineStop = YStop;
emh203 0:7798270c1f52 1557 }
emh203 0:7798270c1f52 1558
emh203 0:7798270c1f52 1559 if(LineStart<0)
emh203 0:7798270c1f52 1560 {
emh203 0:7798270c1f52 1561 LineStart = 0;
emh203 0:7798270c1f52 1562 }
emh203 0:7798270c1f52 1563
emh203 0:7798270c1f52 1564
emh203 0:7798270c1f52 1565 if(LineStop>Image->SizeY)
emh203 0:7798270c1f52 1566 {
emh203 0:7798270c1f52 1567 LineStop = Image->SizeY-1;
emh203 0:7798270c1f52 1568 }
emh203 0:7798270c1f52 1569
emh203 0:7798270c1f52 1570 for(i=LineStart; i<=LineStop ; i++)
emh203 0:7798270c1f52 1571 {
emh203 0:7798270c1f52 1572 GFX_PutPixel(Image,X,i);
emh203 0:7798270c1f52 1573 }
emh203 0:7798270c1f52 1574 }
emh203 0:7798270c1f52 1575 }
emh203 0:7798270c1f52 1576
emh203 0:7798270c1f52 1577
emh203 0:7798270c1f52 1578 void GFX_DrawLine(RenderContext * Image, int16_t X1,int16_t Y1, int16_t X2,int16_t Y2)
emh203 0:7798270c1f52 1579 {
emh203 0:7798270c1f52 1580 //A simple Implementation of Bresenham's line Algorithm
emh203 0:7798270c1f52 1581 int16_t StartX,StopX,StartY,StopY;
emh203 0:7798270c1f52 1582 int16_t dX,dY;
emh203 0:7798270c1f52 1583 int16_t Y_Numerator;
emh203 0:7798270c1f52 1584 int16_t X_Numerator;
emh203 0:7798270c1f52 1585 int16_t Y;
emh203 0:7798270c1f52 1586 int16_t X;
emh203 0:7798270c1f52 1587 int16_t i;
emh203 0:7798270c1f52 1588 uint8_t YDir = 0;
emh203 0:7798270c1f52 1589 //First Make sure that it is left to right
emh203 0:7798270c1f52 1590 //If not them flop them
emh203 0:7798270c1f52 1591 if(X2>X1)
emh203 0:7798270c1f52 1592 {
emh203 0:7798270c1f52 1593 StartX = X1;
emh203 0:7798270c1f52 1594 StopX = X2;
emh203 0:7798270c1f52 1595 StartY = Y1;
emh203 0:7798270c1f52 1596 StopY = Y2;
emh203 0:7798270c1f52 1597 }
emh203 0:7798270c1f52 1598 else
emh203 0:7798270c1f52 1599 {
emh203 0:7798270c1f52 1600 StartX = X2;
emh203 0:7798270c1f52 1601 StopX = X1;
emh203 0:7798270c1f52 1602 StartY = Y2;
emh203 0:7798270c1f52 1603 StopY = Y1;
emh203 0:7798270c1f52 1604 }
emh203 0:7798270c1f52 1605 GFX_PutPixel(Image, StopX,StopY);
emh203 0:7798270c1f52 1606 if(StopY>=StartY)
emh203 0:7798270c1f52 1607 {
emh203 0:7798270c1f52 1608 dY = StopY - StartY;
emh203 0:7798270c1f52 1609 YDir = 0;
emh203 0:7798270c1f52 1610 }
emh203 0:7798270c1f52 1611 else
emh203 0:7798270c1f52 1612 {
emh203 0:7798270c1f52 1613 dY = StartY - StopY;
emh203 0:7798270c1f52 1614 YDir = 1;
emh203 0:7798270c1f52 1615 }
emh203 0:7798270c1f52 1616 dX = StopX - StartX;
emh203 0:7798270c1f52 1617 //Now, if the slope is less greater than one, we need to swap all X/Y operations
emh203 0:7798270c1f52 1618 if(dY<=dX)
emh203 0:7798270c1f52 1619 {
emh203 0:7798270c1f52 1620 //Slope is less than one, proceed at normal and step along the x axis
emh203 0:7798270c1f52 1621 Y=StartY; //start the whole part of the Y value at the starting pixeel.
emh203 0:7798270c1f52 1622 X=StartX;
emh203 0:7798270c1f52 1623 //We need to start the numerator of the fraction half way through the fraction so evertyhing rounds at
emh203 0:7798270c1f52 1624 //fraction midpoint
emh203 0:7798270c1f52 1625 Y_Numerator = dX>>1; //The fraction demonimator is assumeed to be dX
emh203 0:7798270c1f52 1626 // out fixed point Y value is Y + (Y_Numerator / dX)
emh203 0:7798270c1f52 1627 //Every time we step the X coordinate by one, we need to step
emh203 0:7798270c1f52 1628 //out Y coordinate by dY/dX. We do this by just adding dY to our
emh203 0:7798270c1f52 1629 //numerator. When the numerator gets bigger than the
emh203 0:7798270c1f52 1630 //denomiator, the increment the whole part by one and decrement the numerator
emh203 0:7798270c1f52 1631 //by the denominator
emh203 0:7798270c1f52 1632 for(i=0;i<dX;i++)
emh203 0:7798270c1f52 1633 {
emh203 0:7798270c1f52 1634 GFX_PutPixel(Image,X,Y);
emh203 0:7798270c1f52 1635 X++;
emh203 0:7798270c1f52 1636 //Now do all the fractional stuff
emh203 0:7798270c1f52 1637 Y_Numerator += dY;
emh203 0:7798270c1f52 1638 if(Y_Numerator >= dX)
emh203 0:7798270c1f52 1639 {
emh203 0:7798270c1f52 1640 Y_Numerator-=dX;
emh203 0:7798270c1f52 1641 if(StopY > StartY)
emh203 0:7798270c1f52 1642 {
emh203 0:7798270c1f52 1643 Y++;
emh203 0:7798270c1f52 1644 }
emh203 0:7798270c1f52 1645 else
emh203 0:7798270c1f52 1646 {
emh203 0:7798270c1f52 1647 Y--;
emh203 0:7798270c1f52 1648 }
emh203 0:7798270c1f52 1649 }
emh203 0:7798270c1f52 1650 }
emh203 0:7798270c1f52 1651 }
emh203 0:7798270c1f52 1652 else
emh203 0:7798270c1f52 1653 {
emh203 0:7798270c1f52 1654 //Same as before by step along the y axis.
emh203 0:7798270c1f52 1655 Y=StartY;
emh203 0:7798270c1f52 1656 X=StartX;
emh203 0:7798270c1f52 1657 X_Numerator = dY>>1;
emh203 0:7798270c1f52 1658 for(i=0;i<dY;i++)
emh203 0:7798270c1f52 1659 {
emh203 0:7798270c1f52 1660 GFX_PutPixel(Image,X,Y);
emh203 0:7798270c1f52 1661 //Now do all the fractional stuff
emh203 0:7798270c1f52 1662 if(YDir)
emh203 0:7798270c1f52 1663 {
emh203 0:7798270c1f52 1664 Y--;
emh203 0:7798270c1f52 1665 }
emh203 0:7798270c1f52 1666 else
emh203 0:7798270c1f52 1667 {
emh203 0:7798270c1f52 1668 Y++;
emh203 0:7798270c1f52 1669 }
emh203 0:7798270c1f52 1670 X_Numerator += dX;
emh203 0:7798270c1f52 1671 if(X_Numerator >= dY)
emh203 0:7798270c1f52 1672 {
emh203 0:7798270c1f52 1673 X_Numerator-=dY;
emh203 0:7798270c1f52 1674 if(StopX > StartX)
emh203 0:7798270c1f52 1675 {
emh203 0:7798270c1f52 1676 X++;
emh203 0:7798270c1f52 1677 }
emh203 0:7798270c1f52 1678 else
emh203 0:7798270c1f52 1679 {
emh203 0:7798270c1f52 1680 X--;
emh203 0:7798270c1f52 1681 }
emh203 0:7798270c1f52 1682 }
emh203 0:7798270c1f52 1683 }
emh203 0:7798270c1f52 1684 }
emh203 0:7798270c1f52 1685 }
emh203 0:7798270c1f52 1686
emh203 0:7798270c1f52 1687 void GFX_DrawBox(RenderContext *Image, GFXDisplayBox *Box)
emh203 0:7798270c1f52 1688 {
emh203 0:7798270c1f52 1689 GFX_DrawHline(Image,Box->P1.X,Box->P2.X,Box->P1.Y);
emh203 0:7798270c1f52 1690 GFX_DrawHline(Image,Box->P1.X,Box->P2.X,Box->P2.Y);
emh203 0:7798270c1f52 1691 GFX_DrawVline(Image,Box->P1.Y,Box->P2.Y,Box->P1.X);
emh203 0:7798270c1f52 1692 GFX_DrawVline(Image,Box->P1.Y,Box->P2.Y,Box->P2.X);
emh203 0:7798270c1f52 1693 }
emh203 0:7798270c1f52 1694
emh203 0:7798270c1f52 1695 int16_t GFX_DrawCharacter(RenderContext * Image,uint8_t Character,int16_t StartX, int16_t StartY, GFXFont * MyFont)
emh203 0:7798270c1f52 1696 {
emh203 0:7798270c1f52 1697 uint8_t i,j,Mask;
emh203 0:7798270c1f52 1698 uint16_t CharStartIndex,ColumnStartIndex,ByteOffset;
emh203 0:7798270c1f52 1699
emh203 0:7798270c1f52 1700 CharStartIndex = (Character * (MyFont->BytesPerColumn) * (MyFont->FontWidth));
emh203 0:7798270c1f52 1701
emh203 0:7798270c1f52 1702 for(j=0;j<MyFont->CharacterWidthTable[Character];j++)
emh203 0:7798270c1f52 1703 {
emh203 0:7798270c1f52 1704 //Draw the current slice
emh203 0:7798270c1f52 1705 ColumnStartIndex = j* (MyFont->BytesPerColumn);
emh203 0:7798270c1f52 1706
emh203 0:7798270c1f52 1707 for(i=0;i<MyFont->FontHeight;i++)
emh203 0:7798270c1f52 1708 {
emh203 0:7798270c1f52 1709 ByteOffset = i>>3;
emh203 0:7798270c1f52 1710 Mask = 0x01 << (i&0x07);
emh203 0:7798270c1f52 1711
emh203 0:7798270c1f52 1712 if( (MyFont->FontBuffer[CharStartIndex + ColumnStartIndex + ByteOffset]) & Mask)
emh203 0:7798270c1f52 1713 {
emh203 0:7798270c1f52 1714 GFX_PutPixel(Image, StartX, StartY + i);
emh203 0:7798270c1f52 1715 }
emh203 0:7798270c1f52 1716 }
emh203 0:7798270c1f52 1717 StartX++;
emh203 0:7798270c1f52 1718 }
emh203 0:7798270c1f52 1719 return StartX;
emh203 0:7798270c1f52 1720 }
emh203 0:7798270c1f52 1721
emh203 0:7798270c1f52 1722
emh203 0:7798270c1f52 1723 int16_t GFX_GetStringWidth(char * String,GFXFont * MyFont)
emh203 0:7798270c1f52 1724 {
emh203 0:7798270c1f52 1725 uint8_t Ptr = 0;
emh203 0:7798270c1f52 1726 uint8_t NextChar;
emh203 0:7798270c1f52 1727 int16_t StringSize = 0;
emh203 0:7798270c1f52 1728
emh203 0:7798270c1f52 1729 NextChar = String[Ptr];
emh203 0:7798270c1f52 1730 Ptr++;
emh203 0:7798270c1f52 1731
emh203 0:7798270c1f52 1732 while((NextChar!=0) && (Ptr <GFX_MAX_STRING_LEN))
emh203 0:7798270c1f52 1733 {
emh203 0:7798270c1f52 1734 StringSize += MyFont->CharacterWidthTable[NextChar] + 1;
emh203 0:7798270c1f52 1735 NextChar = String[Ptr];
emh203 0:7798270c1f52 1736 Ptr++;
emh203 0:7798270c1f52 1737 }
emh203 0:7798270c1f52 1738
emh203 0:7798270c1f52 1739 return StringSize;
emh203 0:7798270c1f52 1740 }
emh203 0:7798270c1f52 1741
emh203 0:7798270c1f52 1742 void GFX_DrawCenteredString(RenderContext * Image,char * String,int16_t StartX, int16_t StartY, GFXFont * MyFont)
emh203 0:7798270c1f52 1743 {
emh203 0:7798270c1f52 1744 StartX -= (GFX_GetStringWidth(String,MyFont)>>1);
emh203 0:7798270c1f52 1745 GFX_DrawString(Image,String,StartX,StartY,MyFont);
emh203 0:7798270c1f52 1746 }
emh203 0:7798270c1f52 1747
emh203 0:7798270c1f52 1748 void GFX_DrawString(RenderContext * Image,char * String,int16_t StartX, int16_t StartY, GFXFont * MyFont)
emh203 0:7798270c1f52 1749 {
emh203 0:7798270c1f52 1750
emh203 0:7798270c1f52 1751 uint8_t Ptr = 0;
emh203 0:7798270c1f52 1752 uint8_t NextChar;
emh203 0:7798270c1f52 1753
emh203 0:7798270c1f52 1754 NextChar = String[Ptr];
emh203 0:7798270c1f52 1755
emh203 0:7798270c1f52 1756 while((NextChar!=0) && (Ptr <GFX_MAX_STRING_LEN))
emh203 0:7798270c1f52 1757 {
emh203 0:7798270c1f52 1758 StartX = GFX_DrawCharacter(Image,NextChar,StartX,StartY,MyFont);
emh203 0:7798270c1f52 1759 Ptr++;
emh203 0:7798270c1f52 1760 NextChar = String[Ptr];
emh203 0:7798270c1f52 1761 StartX++;
emh203 0:7798270c1f52 1762 }
emh203 0:7798270c1f52 1763
emh203 0:7798270c1f52 1764 }
emh203 0:7798270c1f52 1765
emh203 0:7798270c1f52 1766 char GFXStringBuf[64];
emh203 0:7798270c1f52 1767
emh203 0:7798270c1f52 1768 void GFX_printf(RenderContext * Image,int16_t StartX, int16_t StartY, GFXFont * MyFont, const char *FormatString,...)
emh203 0:7798270c1f52 1769 {
emh203 0:7798270c1f52 1770 va_list argptr;
emh203 0:7798270c1f52 1771 va_start(argptr,FormatString);
emh203 0:7798270c1f52 1772 vsprintf((char *)GFXStringBuf,FormatString,argptr);
emh203 0:7798270c1f52 1773 va_end(argptr);
emh203 0:7798270c1f52 1774
emh203 0:7798270c1f52 1775 GFX_DrawString(Image,GFXStringBuf,StartX,StartY,MyFont);
emh203 0:7798270c1f52 1776 }
emh203 0:7798270c1f52 1777
emh203 0:7798270c1f52 1778 #ifndef INLINE_BITPLANE_PUT
emh203 0:7798270c1f52 1779 void BitPlane_Put(BitPlane * BP, uint16_t X,uint16_t Y, uint8_t Value)
emh203 0:7798270c1f52 1780 {
emh203 0:7798270c1f52 1781 uint16_t Offset;
emh203 0:7798270c1f52 1782 uint8_t Mask;
emh203 0:7798270c1f52 1783
emh203 0:7798270c1f52 1784 Offset = (Y * ((BP->SizeX)>>3)) + (X>>3);
emh203 0:7798270c1f52 1785 Mask = 0x01 << (X & 0x07);
emh203 0:7798270c1f52 1786
emh203 0:7798270c1f52 1787 if(Value)
emh203 0:7798270c1f52 1788 {
emh203 0:7798270c1f52 1789 BP->BitPlaneSpace[Offset] |= Mask;
emh203 0:7798270c1f52 1790 }
emh203 0:7798270c1f52 1791 else
emh203 0:7798270c1f52 1792 {
emh203 0:7798270c1f52 1793 BP->BitPlaneSpace[Offset] &= ~Mask;
emh203 0:7798270c1f52 1794 }
emh203 0:7798270c1f52 1795 }
emh203 0:7798270c1f52 1796 #endif
emh203 0:7798270c1f52 1797
emh203 0:7798270c1f52 1798 #ifndef INLINE_BITPLANE_GET
emh203 0:7798270c1f52 1799 uint8_t BitPlane_Get(BitPlane * BP, uint16_t X,uint16_t Y)
emh203 0:7798270c1f52 1800 {
emh203 0:7798270c1f52 1801 uint16_t Offset;
emh203 0:7798270c1f52 1802 uint8_t Mask;
emh203 0:7798270c1f52 1803
emh203 0:7798270c1f52 1804 Offset = (Y * ((BP->SizeX)>>3)) + (X>>3);
emh203 0:7798270c1f52 1805 Mask = 0x01 << (X & 0x07);
emh203 0:7798270c1f52 1806
emh203 0:7798270c1f52 1807 if((BP->BitPlaneSpace[Offset])&Mask)
emh203 0:7798270c1f52 1808 {
emh203 0:7798270c1f52 1809 return TRUE;
emh203 0:7798270c1f52 1810 }
emh203 0:7798270c1f52 1811 else
emh203 0:7798270c1f52 1812 {
emh203 0:7798270c1f52 1813 return FALSE;
emh203 0:7798270c1f52 1814 }
emh203 0:7798270c1f52 1815 }
emh203 0:7798270c1f52 1816 #endif
emh203 0:7798270c1f52 1817
emh203 0:7798270c1f52 1818 void BitPlane_Clear(BitPlane * BP)
emh203 0:7798270c1f52 1819 {
emh203 0:7798270c1f52 1820 uint16_t PlaneSpaceSize;
emh203 0:7798270c1f52 1821 uint16_t i;
emh203 0:7798270c1f52 1822
emh203 0:7798270c1f52 1823 PlaneSpaceSize = ((BP->SizeX)>>3) * BP->SizeY;
emh203 0:7798270c1f52 1824
emh203 0:7798270c1f52 1825 for (i=0;i<PlaneSpaceSize;i++) {
emh203 0:7798270c1f52 1826 BP->BitPlaneSpace[i] = 0;
emh203 0:7798270c1f52 1827 }
emh203 0:7798270c1f52 1828 }