Temporary Connector Reversed Version

Dependencies:   UniGraphic mbed vt100

afero_poc15_180403R , J1 のピン配置を反転させたヴァージョンです。

Color2系を使用するためには以下のピンをジャンパで接続してください。
J1-D7 <-> J1-D0
J1-D6 <-> J1-D1

(調査中) また、こちらでテストした範囲では、
FRDM-KL25Z の V3.3 を、Modulo2 の VCC_3V3 ピンに接続してやる必要がありました。

尚、J1-D1, D0 を使用するために UART を無効にしているため
ログは表示されません。

TFTモジュールについて 
aitendoのTFTモジュールはデフォルトでは8bit bus モードになっています。
/media/uploads/Rhyme/img_2364.jpg

半田のジャンパを変えて、SPIの設定にしてください。
/media/uploads/Rhyme/img_2363.jpg

サーミスタについて
POC1.5 では サーミスタは 25℃の時に抵抗値が 50.0kΩになる502AT-11 が
4.95kΩのプルアップ(実際は10kΩx2の並列)で使用されていました。

今回の試作では抵抗値が 10.0kΩの 103AT-11 が
5.1kΩのプルアップで使用されていますので、係数を合わせるために
SMTC502AT-11 のコンストラクタを 
R0 = 10.0
R1 = 5.1
B = 3435
T0 = 298.15
で呼ぶように変更しました。

Committer:
Rhyme
Date:
Tue Apr 24 12:18:10 2018 +0000
Revision:
1:6c54dc8acf96
Parent:
0:0b6732b53bf4
to adjust with 103AT-11 with 5.1k pull-up, the constructor of 502AT-11 is called with R0=10.0, R1=5.1, B=3435, T0=298.15

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:0b6732b53bf4 1 /*
Rhyme 0:0b6732b53bf4 2 * File description here
Rhyme 0:0b6732b53bf4 3 */
Rhyme 0:0b6732b53bf4 4 #include "VEML6040.h"
Rhyme 0:0b6732b53bf4 5 #include "af_mgr.h"
Rhyme 0:0b6732b53bf4 6
Rhyme 0:0b6732b53bf4 7 /* VEML6075 SLAVE ADDRESS AND FUNCTION DESCRIPTION */
Rhyme 0:0b6732b53bf4 8 #define REG_COLOR_CONF 0x00
Rhyme 0:0b6732b53bf4 9 #define REG_Reserved1 0x01
Rhyme 0:0b6732b53bf4 10 #define REG_Reserved2 0x02
Rhyme 0:0b6732b53bf4 11 #define REG_Reserved3 0x03
Rhyme 0:0b6732b53bf4 12 #define REG_Reserved4 0x04
Rhyme 0:0b6732b53bf4 13 #define REG_Reserved5 0x05
Rhyme 0:0b6732b53bf4 14 #define REG_Reserved6 0x06
Rhyme 0:0b6732b53bf4 15 #define REG_Reserved7 0x07
Rhyme 0:0b6732b53bf4 16 #define REG_R_Data 0x08
Rhyme 0:0b6732b53bf4 17 #define REG_G_Data 0x09
Rhyme 0:0b6732b53bf4 18 #define REG_B_Data 0x0A
Rhyme 0:0b6732b53bf4 19 #define REG_W_Data 0x0B
Rhyme 0:0b6732b53bf4 20
Rhyme 0:0b6732b53bf4 21 // Following magic numbers are from
Rhyme 0:0b6732b53bf4 22 // VISHAY VEML6040 Application Note 84331
Rhyme 0:0b6732b53bf4 23 // Page 4
Rhyme 0:0b6732b53bf4 24 #define LUX_RESOLUTION_0 (0.25168)
Rhyme 0:0b6732b53bf4 25 #define LUX_RESOLUTION_1 (0.12584)
Rhyme 0:0b6732b53bf4 26 #define LUX_RESOLUTION_2 (0.06292)
Rhyme 0:0b6732b53bf4 27 #define LUX_RESOLUTION_3 (0.03146)
Rhyme 0:0b6732b53bf4 28 #define LUX_RESOLUTION_4 (0.01573)
Rhyme 0:0b6732b53bf4 29 #define LUX_RESOLUTION_5 (0.007865)
Rhyme 0:0b6732b53bf4 30
Rhyme 0:0b6732b53bf4 31 // Following magic numbers are from
Rhyme 0:0b6732b53bf4 32 // VISHAY VEML6040 Application Note 84331
Rhyme 0:0b6732b53bf4 33 // Page 9
Rhyme 0:0b6732b53bf4 34 #define CORR_COEFF_M0 (0.048403)
Rhyme 0:0b6732b53bf4 35 #define CORR_COEFF_M1 (0.183633)
Rhyme 0:0b6732b53bf4 36 #define CORR_COEFF_M2 (-0.253589)
Rhyme 0:0b6732b53bf4 37 #define CORR_COEFF_M3 (0.022916)
Rhyme 0:0b6732b53bf4 38 #define CORR_COEFF_M4 (0.176388)
Rhyme 0:0b6732b53bf4 39 #define CORR_COEFF_M5 (-0.183205)
Rhyme 0:0b6732b53bf4 40 #define CORR_COEFF_M6 (-0.077436)
Rhyme 0:0b6732b53bf4 41 #define CORR_COEFF_M7 (0.124541)
Rhyme 0:0b6732b53bf4 42 #define CORR_COEFF_M8 (0.032081)
Rhyme 0:0b6732b53bf4 43
Rhyme 0:0b6732b53bf4 44 // Following magic numbers are from
Rhyme 0:0b6732b53bf4 45 // VISHAY VEML6040 Application Note 84331
Rhyme 0:0b6732b53bf4 46 // Page 10
Rhyme 0:0b6732b53bf4 47 #define CCT_CONST (4278.6)
Rhyme 0:0b6732b53bf4 48 #define OFFSET_OPEN_AIR (0.5)
Rhyme 0:0b6732b53bf4 49
Rhyme 0:0b6732b53bf4 50 VEML6040::VEML6040(I2C *i2c, int addr) : m_addr(addr<<1) {
Rhyme 0:0b6732b53bf4 51 p_i2c = i2c ;
Rhyme 0:0b6732b53bf4 52 p_i2c->frequency(100000); /* 100kHz */
Rhyme 0:0b6732b53bf4 53 // activate the peripheral
Rhyme 0:0b6732b53bf4 54 }
Rhyme 0:0b6732b53bf4 55
Rhyme 0:0b6732b53bf4 56 VEML6040::~VEML6040() { }
Rhyme 0:0b6732b53bf4 57
Rhyme 0:0b6732b53bf4 58 /**
Rhyme 0:0b6732b53bf4 59 * set COLOR Config
Rhyme 0:0b6732b53bf4 60 * @param colorconf uint8_t 8bit register value
Rhyme 0:0b6732b53bf4 61 * @returns 0: success non-0: failure
Rhyme 0:0b6732b53bf4 62 * @note Command Code 0x00 is used to access CONF register
Rhyme 0:0b6732b53bf4 63 * @note bit[7] (reserved)
Rhyme 0:0b6732b53bf4 64 * @note bit[6:4] = IT[2:0] Integration Time Selector
Rhyme 0:0b6732b53bf4 65 * @note bit[3] (reserved)
Rhyme 0:0b6732b53bf4 66 * @note bit[2] TRIG Proceed one detcting cycle at manual force mode
Rhyme 0:0b6732b53bf4 67 * @note bit[1] AF 0: Auto mode 1: manual force mode
Rhyme 0:0b6732b53bf4 68 * @note bit[0] SD 0: normal 1: chip shutdown setting
Rhyme 0:0b6732b53bf4 69 *
Rhyme 0:0b6732b53bf4 70 * @note IT[2:0] 0=40ms, 1=80ms, 2=160ms, 3=320ms, 4=640ms, 5=1280ms
Rhyme 0:0b6732b53bf4 71 * @note as our WatchDog is set to 1sec, 1280ms is invalid
Rhyme 0:0b6732b53bf4 72 * @note and 640ms may not be practical
Rhyme 0:0b6732b53bf4 73 */
Rhyme 0:0b6732b53bf4 74 int VEML6040::setCOLORConf(uint8_t colorconf)
Rhyme 0:0b6732b53bf4 75 {
Rhyme 0:0b6732b53bf4 76 int result ;
Rhyme 0:0b6732b53bf4 77 uint8_t data[3] ;
Rhyme 0:0b6732b53bf4 78 data[0] = REG_COLOR_CONF ;
Rhyme 0:0b6732b53bf4 79 data[1] = colorconf ;
Rhyme 0:0b6732b53bf4 80 data[2] = 0 ;
Rhyme 0:0b6732b53bf4 81 result = writeRegs(data, 3) ;
Rhyme 0:0b6732b53bf4 82 return( result ) ;
Rhyme 0:0b6732b53bf4 83 }
Rhyme 0:0b6732b53bf4 84
Rhyme 0:0b6732b53bf4 85 /**
Rhyme 0:0b6732b53bf4 86 * get COLOR Config
Rhyme 0:0b6732b53bf4 87 * @param *colorconf uint8_t refer to setCOLORConf for the value
Rhyme 0:0b6732b53bf4 88 * @returns 0: success non-0: failure
Rhyme 0:0b6732b53bf4 89 */
Rhyme 0:0b6732b53bf4 90 int VEML6040::getCOLORConf(uint8_t *colorconf)
Rhyme 0:0b6732b53bf4 91 {
Rhyme 0:0b6732b53bf4 92 int result ;
Rhyme 0:0b6732b53bf4 93 uint8_t data[2] ;
Rhyme 0:0b6732b53bf4 94 result = readRegs(REG_COLOR_CONF, data, 2) ;
Rhyme 0:0b6732b53bf4 95 if (result == 0) {
Rhyme 0:0b6732b53bf4 96 *colorconf = data[0] ;
Rhyme 0:0b6732b53bf4 97 }
Rhyme 0:0b6732b53bf4 98 return( result ) ;
Rhyme 0:0b6732b53bf4 99 }
Rhyme 0:0b6732b53bf4 100
Rhyme 0:0b6732b53bf4 101
Rhyme 0:0b6732b53bf4 102
Rhyme 0:0b6732b53bf4 103 int VEML6040::getRData(uint16_t *rdata)
Rhyme 0:0b6732b53bf4 104 {
Rhyme 0:0b6732b53bf4 105 uint8_t data[2] ;
Rhyme 0:0b6732b53bf4 106 int result ;
Rhyme 0:0b6732b53bf4 107 result = readRegs(REG_R_Data, data, 2) ;
Rhyme 0:0b6732b53bf4 108 *rdata = (data[1]<<8) | data[0] ;
Rhyme 0:0b6732b53bf4 109 return( result ) ;
Rhyme 0:0b6732b53bf4 110 }
Rhyme 0:0b6732b53bf4 111
Rhyme 0:0b6732b53bf4 112 int VEML6040::getGData(uint16_t *gdata)
Rhyme 0:0b6732b53bf4 113 {
Rhyme 0:0b6732b53bf4 114 uint8_t data[2] ;
Rhyme 0:0b6732b53bf4 115 int result ;
Rhyme 0:0b6732b53bf4 116 result = readRegs(REG_G_Data, data, 2) ;
Rhyme 0:0b6732b53bf4 117 *gdata = (data[1]<<8) | data[0] ;
Rhyme 0:0b6732b53bf4 118 return( result ) ;
Rhyme 0:0b6732b53bf4 119 }
Rhyme 0:0b6732b53bf4 120
Rhyme 0:0b6732b53bf4 121 int VEML6040::getBData(uint16_t *bdata)
Rhyme 0:0b6732b53bf4 122 {
Rhyme 0:0b6732b53bf4 123 uint8_t data[2] ;
Rhyme 0:0b6732b53bf4 124 int result ;
Rhyme 0:0b6732b53bf4 125 result = readRegs(REG_B_Data, data, 2) ;
Rhyme 0:0b6732b53bf4 126 *bdata = (data[1]<<8) | data[0] ;
Rhyme 0:0b6732b53bf4 127 return( result ) ;
Rhyme 0:0b6732b53bf4 128 }
Rhyme 0:0b6732b53bf4 129
Rhyme 0:0b6732b53bf4 130 int VEML6040::getWData(uint16_t *wdata)
Rhyme 0:0b6732b53bf4 131 {
Rhyme 0:0b6732b53bf4 132 uint8_t data[2] ;
Rhyme 0:0b6732b53bf4 133 int result ;
Rhyme 0:0b6732b53bf4 134 result = readRegs(REG_W_Data, data, 2) ;
Rhyme 0:0b6732b53bf4 135 *wdata = (data[1]<<8) | data[0] ;
Rhyme 0:0b6732b53bf4 136 return( result ) ;
Rhyme 0:0b6732b53bf4 137 }
Rhyme 0:0b6732b53bf4 138
Rhyme 0:0b6732b53bf4 139 // usage
Rhyme 0:0b6732b53bf4 140 // fvalue = veml->getUVA() ;
Rhyme 0:0b6732b53bf4 141 // printf("%f", fvalue) ;
Rhyme 0:0b6732b53bf4 142 float VEML6040::getR(void)
Rhyme 0:0b6732b53bf4 143 {
Rhyme 0:0b6732b53bf4 144 uint16_t data ;
Rhyme 0:0b6732b53bf4 145 float value ;
Rhyme 0:0b6732b53bf4 146 getRData(&data) ;
Rhyme 0:0b6732b53bf4 147 value = (float)LUX_RESOLUTION_0 * (float)data ;
Rhyme 0:0b6732b53bf4 148 return( value ) ;
Rhyme 0:0b6732b53bf4 149 }
Rhyme 0:0b6732b53bf4 150
Rhyme 0:0b6732b53bf4 151 float VEML6040::getG(void)
Rhyme 0:0b6732b53bf4 152 {
Rhyme 0:0b6732b53bf4 153 uint16_t data ;
Rhyme 0:0b6732b53bf4 154 float value ;
Rhyme 0:0b6732b53bf4 155 getGData(&data) ;
Rhyme 0:0b6732b53bf4 156 value = (float)LUX_RESOLUTION_0 * (float)data ;
Rhyme 0:0b6732b53bf4 157 return( value ) ;
Rhyme 0:0b6732b53bf4 158 }
Rhyme 0:0b6732b53bf4 159
Rhyme 0:0b6732b53bf4 160 float VEML6040::getB(void)
Rhyme 0:0b6732b53bf4 161 {
Rhyme 0:0b6732b53bf4 162 uint16_t data ;
Rhyme 0:0b6732b53bf4 163 float value ;
Rhyme 0:0b6732b53bf4 164 getBData(&data) ;
Rhyme 0:0b6732b53bf4 165 value = (float)LUX_RESOLUTION_0 * (float)data ;
Rhyme 0:0b6732b53bf4 166 return( value ) ;
Rhyme 0:0b6732b53bf4 167 }
Rhyme 0:0b6732b53bf4 168
Rhyme 0:0b6732b53bf4 169 float VEML6040::getW(void)
Rhyme 0:0b6732b53bf4 170 {
Rhyme 0:0b6732b53bf4 171 uint16_t data ;
Rhyme 0:0b6732b53bf4 172 float value ;
Rhyme 0:0b6732b53bf4 173 getWData(&data) ;
Rhyme 0:0b6732b53bf4 174 value = (float)LUX_RESOLUTION_0 * (float)data ;
Rhyme 0:0b6732b53bf4 175 return( value ) ;
Rhyme 0:0b6732b53bf4 176 }
Rhyme 0:0b6732b53bf4 177
Rhyme 0:0b6732b53bf4 178 float VEML6040::getX(void)
Rhyme 0:0b6732b53bf4 179 {
Rhyme 0:0b6732b53bf4 180 uint16_t R ;
Rhyme 0:0b6732b53bf4 181 uint16_t G ;
Rhyme 0:0b6732b53bf4 182 uint16_t B ;
Rhyme 0:0b6732b53bf4 183 float value ;
Rhyme 0:0b6732b53bf4 184 getRData(&R) ;
Rhyme 0:0b6732b53bf4 185 getGData(&G) ;
Rhyme 0:0b6732b53bf4 186 getBData(&B) ;
Rhyme 0:0b6732b53bf4 187 value = (float)CORR_COEFF_M0 * (float)R + (float)CORR_COEFF_M1 * (float)G + (float)CORR_COEFF_M2 * (float)B ;
Rhyme 0:0b6732b53bf4 188 return( value ) ;
Rhyme 0:0b6732b53bf4 189 }
Rhyme 0:0b6732b53bf4 190
Rhyme 0:0b6732b53bf4 191 float VEML6040::getY(void)
Rhyme 0:0b6732b53bf4 192 {
Rhyme 0:0b6732b53bf4 193 uint16_t R ;
Rhyme 0:0b6732b53bf4 194 uint16_t G ;
Rhyme 0:0b6732b53bf4 195 uint16_t B ;
Rhyme 0:0b6732b53bf4 196 float value ;
Rhyme 0:0b6732b53bf4 197 getRData(&R) ;
Rhyme 0:0b6732b53bf4 198 getGData(&G) ;
Rhyme 0:0b6732b53bf4 199 getBData(&B) ;
Rhyme 0:0b6732b53bf4 200 value = (float)CORR_COEFF_M3 * (float)R + (float)CORR_COEFF_M4 * (float)G + (float)CORR_COEFF_M5 * (float)B ;
Rhyme 0:0b6732b53bf4 201 return( value ) ;
Rhyme 0:0b6732b53bf4 202 }
Rhyme 0:0b6732b53bf4 203
Rhyme 0:0b6732b53bf4 204 float VEML6040::getZ(void)
Rhyme 0:0b6732b53bf4 205 {
Rhyme 0:0b6732b53bf4 206 uint16_t R ;
Rhyme 0:0b6732b53bf4 207 uint16_t G ;
Rhyme 0:0b6732b53bf4 208 uint16_t B ;
Rhyme 0:0b6732b53bf4 209 float value ;
Rhyme 0:0b6732b53bf4 210 getRData(&R) ;
Rhyme 0:0b6732b53bf4 211 getGData(&G) ;
Rhyme 0:0b6732b53bf4 212 getBData(&B) ;
Rhyme 0:0b6732b53bf4 213 value = (float)CORR_COEFF_M6 * (float)R + (float)CORR_COEFF_M7 * (float)G + (float)CORR_COEFF_M8 * (float)B ;
Rhyme 0:0b6732b53bf4 214 return( value ) ;
Rhyme 0:0b6732b53bf4 215 }
Rhyme 0:0b6732b53bf4 216
Rhyme 0:0b6732b53bf4 217 float VEML6040::getCCTiData(void)
Rhyme 0:0b6732b53bf4 218 {
Rhyme 0:0b6732b53bf4 219 uint16_t rdata ;
Rhyme 0:0b6732b53bf4 220 uint16_t gdata ;
Rhyme 0:0b6732b53bf4 221 uint16_t bdata ;
Rhyme 0:0b6732b53bf4 222 float value ;
Rhyme 0:0b6732b53bf4 223 getRData(&rdata) ;
Rhyme 0:0b6732b53bf4 224 getGData(&gdata) ;
Rhyme 0:0b6732b53bf4 225 getBData(&bdata) ;
Rhyme 0:0b6732b53bf4 226 value = ((float)rdata - (float)bdata) / (float)gdata + (float)OFFSET_OPEN_AIR ;
Rhyme 0:0b6732b53bf4 227 return( value ) ;
Rhyme 0:0b6732b53bf4 228 }
Rhyme 0:0b6732b53bf4 229
Rhyme 0:0b6732b53bf4 230 float VEML6040::getCCTData(void)
Rhyme 0:0b6732b53bf4 231 {
Rhyme 0:0b6732b53bf4 232 // uint16_t cctidata ;
Rhyme 0:0b6732b53bf4 233 float cctidata ;
Rhyme 0:0b6732b53bf4 234 float value ;
Rhyme 0:0b6732b53bf4 235 cctidata = getCCTiData() ;
Rhyme 0:0b6732b53bf4 236 // getCCTiData(&cctidata) ;
Rhyme 0:0b6732b53bf4 237 value = (float)CCT_CONST * powf( cctidata, -1.2455 ) ;
Rhyme 0:0b6732b53bf4 238 return( value ) ;
Rhyme 0:0b6732b53bf4 239 }
Rhyme 0:0b6732b53bf4 240
Rhyme 0:0b6732b53bf4 241 float VEML6040::getCIEX(void)
Rhyme 0:0b6732b53bf4 242 {
Rhyme 0:0b6732b53bf4 243 float X ;
Rhyme 0:0b6732b53bf4 244 float Y ;
Rhyme 0:0b6732b53bf4 245 float Z ;
Rhyme 0:0b6732b53bf4 246 float value ;
Rhyme 0:0b6732b53bf4 247 X = getX() ;
Rhyme 0:0b6732b53bf4 248 Y = getY() ;
Rhyme 0:0b6732b53bf4 249 Z = getZ() ;
Rhyme 0:0b6732b53bf4 250 value = (float)X / ((float)X + (float)Y + (float)Z) ;
Rhyme 0:0b6732b53bf4 251 return( value ) ;
Rhyme 0:0b6732b53bf4 252 }
Rhyme 0:0b6732b53bf4 253
Rhyme 0:0b6732b53bf4 254 float VEML6040::getCIEY(void)
Rhyme 0:0b6732b53bf4 255 {
Rhyme 0:0b6732b53bf4 256 float X ;
Rhyme 0:0b6732b53bf4 257 float Y ;
Rhyme 0:0b6732b53bf4 258 float Z ;
Rhyme 0:0b6732b53bf4 259 float value ;
Rhyme 0:0b6732b53bf4 260 X = getX() ;
Rhyme 0:0b6732b53bf4 261 Y = getY() ;
Rhyme 0:0b6732b53bf4 262 Z = getZ() ;
Rhyme 0:0b6732b53bf4 263 value = (float)Y / ((float)X + (float)Y + (float)Z) ;
Rhyme 0:0b6732b53bf4 264 return( value ) ;
Rhyme 0:0b6732b53bf4 265 }
Rhyme 0:0b6732b53bf4 266
Rhyme 0:0b6732b53bf4 267 int VEML6040::readRegs(int addr, uint8_t * data, int len) {
Rhyme 0:0b6732b53bf4 268 char t[1] = {addr};
Rhyme 0:0b6732b53bf4 269 int result ;
Rhyme 0:0b6732b53bf4 270 __disable_irq() ; // Disable Interrupts
Rhyme 0:0b6732b53bf4 271 result = p_i2c->write(m_addr, t, 1, true);
Rhyme 0:0b6732b53bf4 272 if (result == 0) { // write success
Rhyme 0:0b6732b53bf4 273 result = p_i2c->read(m_addr, (char *)data, len, false);
Rhyme 0:0b6732b53bf4 274 }
Rhyme 0:0b6732b53bf4 275 __enable_irq() ; // Enable Interrupts
Rhyme 0:0b6732b53bf4 276 return(result) ;
Rhyme 0:0b6732b53bf4 277 }
Rhyme 0:0b6732b53bf4 278
Rhyme 0:0b6732b53bf4 279 int VEML6040::writeRegs(uint8_t * data, int len) {
Rhyme 0:0b6732b53bf4 280 int result ;
Rhyme 0:0b6732b53bf4 281 __disable_irq() ; // Disable Interrupts
Rhyme 0:0b6732b53bf4 282 result = p_i2c->write(m_addr, (char *)data, len);
Rhyme 0:0b6732b53bf4 283 __enable_irq() ; // Enable Interrupts
Rhyme 0:0b6732b53bf4 284 return(result) ;
Rhyme 0:0b6732b53bf4 285 }