Eli Hughes
/
RobotPowerLogger-V2
For Terrance
Code/SmartSwitch.c@0:085749c8446f, 2012-06-13 (annotated)
- Committer:
- emh203
- Date:
- Wed Jun 13 15:10:06 2012 +0000
- Revision:
- 0:085749c8446f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emh203 | 0:085749c8446f | 1 | #include "System.h" |
emh203 | 0:085749c8446f | 2 | |
emh203 | 0:085749c8446f | 3 | DigitalOut EnableSmartSwitchPower(p27); |
emh203 | 0:085749c8446f | 4 | DigitalOut SmartSwitch_SS(p24); |
emh203 | 0:085749c8446f | 5 | DigitalOut SmartSwitch_SCK(p25); |
emh203 | 0:085749c8446f | 6 | DigitalOut SmartSwitch_SDI(p26); |
emh203 | 0:085749c8446f | 7 | |
emh203 | 0:085749c8446f | 8 | void SmartSwitch_ImageDump(BYTE *Img) |
emh203 | 0:085749c8446f | 9 | { |
emh203 | 0:085749c8446f | 10 | int i; |
emh203 | 0:085749c8446f | 11 | |
emh203 | 0:085749c8446f | 12 | SmartSwitch_SS = 0; |
emh203 | 0:085749c8446f | 13 | SmartSwitchWriteByte(SMART_SWITCH_CMD_DISPLAY_DATA); |
emh203 | 0:085749c8446f | 14 | |
emh203 | 0:085749c8446f | 15 | for(i=0;i<256;i++) |
emh203 | 0:085749c8446f | 16 | { |
emh203 | 0:085749c8446f | 17 | SmartSwitchWriteByte(Img[i]); |
emh203 | 0:085749c8446f | 18 | } |
emh203 | 0:085749c8446f | 19 | |
emh203 | 0:085749c8446f | 20 | SmartSwitch_SS = 1; |
emh203 | 0:085749c8446f | 21 | } |
emh203 | 0:085749c8446f | 22 | |
emh203 | 0:085749c8446f | 23 | void SmartSwitchClear() |
emh203 | 0:085749c8446f | 24 | { |
emh203 | 0:085749c8446f | 25 | int i; |
emh203 | 0:085749c8446f | 26 | |
emh203 | 0:085749c8446f | 27 | SmartSwitch_SS = 0; |
emh203 | 0:085749c8446f | 28 | SmartSwitchWriteByte(SMART_SWITCH_CMD_DISPLAY_DATA); |
emh203 | 0:085749c8446f | 29 | |
emh203 | 0:085749c8446f | 30 | for(i=0;i<256;i++) |
emh203 | 0:085749c8446f | 31 | { |
emh203 | 0:085749c8446f | 32 | SmartSwitchWriteByte(0x00); |
emh203 | 0:085749c8446f | 33 | } |
emh203 | 0:085749c8446f | 34 | |
emh203 | 0:085749c8446f | 35 | SmartSwitch_SS = 1; |
emh203 | 0:085749c8446f | 36 | } |
emh203 | 0:085749c8446f | 37 | |
emh203 | 0:085749c8446f | 38 | void SmartSwitch_Reset() |
emh203 | 0:085749c8446f | 39 | { |
emh203 | 0:085749c8446f | 40 | SmartSwitch_SS = 0; |
emh203 | 0:085749c8446f | 41 | SmartSwitchWriteByte(SMART_SWITCH_CMD_RESET); |
emh203 | 0:085749c8446f | 42 | SmartSwitchWriteByte(SMART_SWITCH_CMD_RESET_PARAMETER); |
emh203 | 0:085749c8446f | 43 | SmartSwitch_SS = 1; |
emh203 | 0:085749c8446f | 44 | } |
emh203 | 0:085749c8446f | 45 | |
emh203 | 0:085749c8446f | 46 | void SmartSwitch_SetBackLightColor(BYTE Red,BYTE Green,BYTE Blue) |
emh203 | 0:085749c8446f | 47 | { |
emh203 | 0:085749c8446f | 48 | SmartSwitch_SS = 0; |
emh203 | 0:085749c8446f | 49 | SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BACKLIGHT_COLOR); |
emh203 | 0:085749c8446f | 50 | SmartSwitchWriteByte(Red<<6 | Green<<4 | Blue <<2 | 0x3); |
emh203 | 0:085749c8446f | 51 | SmartSwitch_SS = 1; |
emh203 | 0:085749c8446f | 52 | } |
emh203 | 0:085749c8446f | 53 | |
emh203 | 0:085749c8446f | 54 | void SmartSwitch_SetBackLightColor2(BYTE RGB) |
emh203 | 0:085749c8446f | 55 | { |
emh203 | 0:085749c8446f | 56 | SmartSwitch_SS = 0; |
emh203 | 0:085749c8446f | 57 | SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BACKLIGHT_COLOR); |
emh203 | 0:085749c8446f | 58 | SmartSwitchWriteByte(RGB<<2 | 0x3); |
emh203 | 0:085749c8446f | 59 | SmartSwitch_SS = 1; |
emh203 | 0:085749c8446f | 60 | } |
emh203 | 0:085749c8446f | 61 | |
emh203 | 0:085749c8446f | 62 | void SmartSwitch_SetBrightnss(BYTE Brightness) |
emh203 | 0:085749c8446f | 63 | { |
emh203 | 0:085749c8446f | 64 | SmartSwitch_SS = 0; |
emh203 | 0:085749c8446f | 65 | SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BRIGHTNESS); |
emh203 | 0:085749c8446f | 66 | SmartSwitchWriteByte(Brightness<<5 | 0x1F); |
emh203 | 0:085749c8446f | 67 | SmartSwitch_SS = 1; |
emh203 | 0:085749c8446f | 68 | } |
emh203 | 0:085749c8446f | 69 | |
emh203 | 0:085749c8446f | 70 | |
emh203 | 0:085749c8446f | 71 | |
emh203 | 0:085749c8446f | 72 | void InitSmartSwitch() |
emh203 | 0:085749c8446f | 73 | { |
emh203 | 0:085749c8446f | 74 | SmartSwitch_SS = 1; |
emh203 | 0:085749c8446f | 75 | SmartSwitch_SCK = 1; |
emh203 | 0:085749c8446f | 76 | SmartSwitch_SDI = 1; |
emh203 | 0:085749c8446f | 77 | PowerUpSmartSwitch(); |
emh203 | 0:085749c8446f | 78 | SmartSwitch_Reset(); |
emh203 | 0:085749c8446f | 79 | |
emh203 | 0:085749c8446f | 80 | } |
emh203 | 0:085749c8446f | 81 | |
emh203 | 0:085749c8446f | 82 | void PowerUpSmartSwitch() |
emh203 | 0:085749c8446f | 83 | { |
emh203 | 0:085749c8446f | 84 | EnableSmartSwitchPower = 1; |
emh203 | 0:085749c8446f | 85 | } |
emh203 | 0:085749c8446f | 86 | |
emh203 | 0:085749c8446f | 87 | void PowerDownSmartSwitch() |
emh203 | 0:085749c8446f | 88 | { |
emh203 | 0:085749c8446f | 89 | EnableSmartSwitchPower = 0; |
emh203 | 0:085749c8446f | 90 | } |
emh203 | 0:085749c8446f | 91 | |
emh203 | 0:085749c8446f | 92 | void SmartSwitchWriteByte(BYTE DataOut) |
emh203 | 0:085749c8446f | 93 | { |
emh203 | 0:085749c8446f | 94 | BYTE i; |
emh203 | 0:085749c8446f | 95 | |
emh203 | 0:085749c8446f | 96 | SmartSwitch_SCK = 1; |
emh203 | 0:085749c8446f | 97 | |
emh203 | 0:085749c8446f | 98 | for(i=0;i<8;i++) |
emh203 | 0:085749c8446f | 99 | { |
emh203 | 0:085749c8446f | 100 | if(DataOut & (0x01<<(7-i))) |
emh203 | 0:085749c8446f | 101 | { |
emh203 | 0:085749c8446f | 102 | SmartSwitch_SDI = 1; |
emh203 | 0:085749c8446f | 103 | } |
emh203 | 0:085749c8446f | 104 | else |
emh203 | 0:085749c8446f | 105 | { |
emh203 | 0:085749c8446f | 106 | SmartSwitch_SDI = 0; |
emh203 | 0:085749c8446f | 107 | } |
emh203 | 0:085749c8446f | 108 | |
emh203 | 0:085749c8446f | 109 | SmartSwitch_SCK = 0; |
emh203 | 0:085749c8446f | 110 | SmartSwitch_SCK = 1; |
emh203 | 0:085749c8446f | 111 | } |
emh203 | 0:085749c8446f | 112 | } |
emh203 | 0:085749c8446f | 113 | |
emh203 | 0:085749c8446f | 114 |