Mercurial > public > hwos_code
comparison src/i2c.asm @ 166:30ebaf72170d
BUGFIX: Flip compass with flipped screen, too
BUGFIX: Surface interval was paused during simulator
author | heinrichsweikamp |
---|---|
date | Sun, 28 Sep 2014 18:44:07 +0200 |
parents | 683321c09cfa |
children | dcd513840c6c |
comparison
equal
deleted
inserted
replaced
165:9b82239fa062 | 166:30ebaf72170d |
---|---|
132 rcall I2C_TX | 132 rcall I2C_TX |
133 | 133 |
134 rcall I2C_OneByteRX ; Get Status Byte | 134 rcall I2C_OneByteRX ; Get Status Byte |
135 movf SSP1BUF,W | 135 movf SSP1BUF,W |
136 | 136 |
137 ; Non-flipped screen: | |
137 ; Chip orientation on the PCB requires | 138 ; Chip orientation on the PCB requires |
138 ; Original = Corrected | 139 ; Original = Corrected |
139 ; x = -x | 140 ; x = -x |
140 ; y = -y | 141 ; y = -y |
141 ; z = -z | 142 ; z = -z |
142 | 143 |
144 ; Flipped screen: | |
145 ; Chip orientation on the PCB requires | |
146 ; Original = Corrected | |
147 ; x = x | |
148 ; y = y | |
149 ; z = -z | |
150 | |
143 rcall I2C_TwoBytesRX_div16 ; Get two bytes and devide /16 (signed) | 151 rcall I2C_TwoBytesRX_div16 ; Get two bytes and devide /16 (signed) |
152 btfsc flip_screen ; 180° rotation ? | |
153 bra I2C_RX_accelerometer2 ; Yes | |
144 comf hi ; 16bit sign change. | 154 comf hi ; 16bit sign change. |
145 negf lo | 155 negf lo |
146 btfsc STATUS,C ; Carry to propagate ? | 156 btfsc STATUS,C ; Carry to propagate ? |
147 incf hi,F ; YES: do it. | 157 incf hi,F ; YES: do it. |
158 I2C_RX_accelerometer2: | |
148 movff lo,accel_DX+0 | 159 movff lo,accel_DX+0 |
149 movff hi,accel_DX+1 ; Copy result | 160 movff hi,accel_DX+1 ; Copy result |
150 | 161 |
151 rcall I2C_TwoBytesRX_div16 ; Get two bytes and devide /16 (signed) | 162 rcall I2C_TwoBytesRX_div16 ; Get two bytes and devide /16 (signed) |
163 btfsc flip_screen ; 180° rotation ? | |
164 bra I2C_RX_accelerometer3 ; Yes | |
152 comf hi ; 16bit sign change. | 165 comf hi ; 16bit sign change. |
153 negf lo | 166 negf lo |
154 btfsc STATUS,C ; Carry to propagate ? | 167 btfsc STATUS,C ; Carry to propagate ? |
155 incf hi,F ; YES: do it. | 168 incf hi,F ; YES: do it. |
169 I2C_RX_accelerometer3: | |
156 movff lo,accel_DY+0 | 170 movff lo,accel_DY+0 |
157 movff hi,accel_DY+1 ; Copy result | 171 movff hi,accel_DY+1 ; Copy result |
158 | 172 |
159 rcall I2C_OneByteRX ; Get one byte | 173 rcall I2C_OneByteRX ; Get one byte |
160 movff SSP1BUF,hi ; Data Byte | 174 movff SSP1BUF,hi ; Data Byte |
205 ; z MSB | 219 ; z MSB |
206 ; z LSB | 220 ; z LSB |
207 ; y MSB | 221 ; y MSB |
208 ; y LSB | 222 ; y LSB |
209 | 223 |
224 ; Non-flipped screen | |
210 ; Chip orientation on the PCB requires | 225 ; Chip orientation on the PCB requires |
211 ; Original = Corrected | 226 ; Original = Corrected |
212 ; x = -y | 227 ; x = -y |
213 ; z = z | 228 ; z = z |
214 ; y = x | 229 ; y = x |
215 | 230 |
231 ; Flipped screen | |
232 ; Chip orientation on the PCB requires | |
233 ; Original = Corrected | |
234 ; x = y | |
235 ; z = z | |
236 ; y = -x | |
237 | |
216 rcall I2C_OneByteRX ; Get one byte | 238 rcall I2C_OneByteRX ; Get one byte |
217 movff SSP1BUF,compass_DY+1; Data Byte | 239 movff SSP1BUF,compass_DY+1; Data Byte |
218 rcall I2C_OneByteRX ; Get one byte | 240 rcall I2C_OneByteRX ; Get one byte |
219 movff SSP1BUF,compass_DY+0; Data Byte | 241 movff SSP1BUF,compass_DY+0; Data Byte |
242 btfsc flip_screen ; 180° rotation ? | |
243 bra I2C_RX_compass2 ; Yes | |
220 banksel compass_DY | 244 banksel compass_DY |
221 comf compass_DY+1 ; 16bit sign change. | 245 comf compass_DY+1 ; 16bit sign change. |
222 negf compass_DY+0 | 246 negf compass_DY+0 |
223 btfsc STATUS,C ; Carry to propagate ? | 247 btfsc STATUS,C ; Carry to propagate ? |
224 incf compass_DY+1,F ; YES: do it. | 248 incf compass_DY+1,F ; YES: do it. |
249 I2C_RX_compass2: | |
225 banksel common | 250 banksel common |
226 rcall I2C_OneByteRX ; Get one byte | 251 rcall I2C_OneByteRX ; Get one byte |
227 movff SSP1BUF,compass_DZ+1; Data Byte | 252 movff SSP1BUF,compass_DZ+1; Data Byte |
228 rcall I2C_OneByteRX ; Get one byte | 253 rcall I2C_OneByteRX ; Get one byte |
229 movff SSP1BUF,compass_DZ+0; Data Byte | 254 movff SSP1BUF,compass_DZ+0; Data Byte |
232 bsf SSP1CON2, RCEN ; Enable recieve mode | 257 bsf SSP1CON2, RCEN ; Enable recieve mode |
233 rcall WaitMSSP | 258 rcall WaitMSSP |
234 movff SSP1BUF,compass_DX+0; Data Byte | 259 movff SSP1BUF,compass_DX+0; Data Byte |
235 bsf SSP1CON2,PEN ; Stop condition | 260 bsf SSP1CON2,PEN ; Stop condition |
236 rcall WaitMSSP | 261 rcall WaitMSSP |
262 btfss flip_screen ; 180° rotation ? | |
263 return ; No, done. | |
264 ; Yes, flip X | |
265 banksel compass_DX | |
266 comf compass_DX+1 ; 16bit sign change. | |
267 negf compass_DX+0 | |
268 btfsc STATUS,C ; Carry to propagate ? | |
269 incf compass_DX+1,F ; YES: do it. | |
270 banksel common | |
237 return | 271 return |
238 | 272 |
239 global I2C_init_compass | 273 global I2C_init_compass |
240 I2C_init_compass: | 274 I2C_init_compass: |
241 bsf SSP1CON2,SEN ; Start condition | 275 bsf SSP1CON2,SEN ; Start condition |