Subversion Repositories svn.mios

Rev

Rev 52 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
53 tk 1
; $Id: mios_din.inc 53 2008-01-30 22:52:41Z tk $
1 tk 2
;
3
; MIOS Service Routines for the DIN chain
4
;
5
; ==========================================================================
6
;
7
;  Copyright 1998-2006 Thorsten Klose (tk@midibox.org)
8
;  Licensed for personal non-commercial use only.
9
;  All other rights reserved.
10
;
11
; ==========================================================================
12
 
13
;; --------------------------------------------------------------------------
14
;;  FUNCTION: USER_DIN_NotifyToggle
15
;;  C_DECLARATION: void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value)
16
;;  DESCRIPTION: This function is called by MIOS when an button has been
17
;;  toggled
18
;;  IN: Button number in WREG and MIOS_PARAMETER1
19
;;      Button value MIOS_PARAMETER2:
20
;;        - 1 if button has been released (=5V)
21
;;        - 0 if button has been pressed (=0V)
22
;;  C_IN: Button number in <pin>
23
;;      Button value <pin_value>:
24
;;        - 1 if button has been released (=5V)
25
;;        - 0 if button has been pressed (=0V)
26
;;  OUT:  -
27
;;  ISR: no
28
;; --------------------------------------------------------------------------
29
 
30
;; --------------------------------------------------------------------------
31
;;  FUNCTION: MIOS_DIN_SRGet
32
;;  C_DECLARATION: unsigned char MIOS_DIN_SRGet(unsigned char sr)
33
;;  DESCRIPTION: returns value of DIN shift register
34
;;  IN:	  number of shift register in WREG
35
;;  C_IN: number of shift register in <sr>
36
;;  OUT:  value of shift register in MIOS_PARAMETER1 and WREG,
37
;;        pointer to shift register in FSR1
38
;;  C_OUT: value of shift register
39
;;  USES: FSR1
40
;; --------------------------------------------------------------------------
41
MIOS_DIN_SRGet
42
	andlw	0x0f
43
	lfsr	FSR1, MIOS_SR_DIN_0
44
	addwf	FSR1L, F
45
	movf	INDF1, W
46
	movwf	MIOS_PARAMETER1
47
	return
48
 
49
;; --------------------------------------------------------------------------
50
;;  FUNCTION: MIOS_DIN_PinGet
51
;;  C_DECLARATION: unsigned char MIOS_DIN_PinGet(unsigned char pin)
52
;;  DESCRIPTION: returns value from a DIN Pin
53
;;  IN:	  Pin number in WREG
54
;;  C_IN: Pin number in <pin>
55
;;  OUT:  1 if pin is +5V, 0 if pin is 0V in MIOS_PARAMETER and WREG
56
;;  C_OUT: 1 if pin is +5V, 0 if pin is 0V
57
;;  USES: FSR1 and BSR
58
;; --------------------------------------------------------------------------
59
MIOS_DIN_PinGet
60
	andlw	0x7f
61
	lfsr	FSR1, MIOS_SR_DIN_0
62
	rgoto	MIOS_SRIO_Get
63
 
64
;; --------------------------------------------------------------------------
65
;;  FUNCTION: MIOS_DIN_PinAutoRepeatEnable
66
;;  C_DECLARATION: void MIOS_DIN_PinAutoRepeatEnable(unsigned char pin)
67
;;  DESCRIPTION: enables the auto-repeat feature for the appr. pin
68
;;  IN:	  number of pin in WREG
69
;;  C_IN:  number of pin in <pin>
70
;;  OUT:  -
71
;;  C_OUT:  -
72
;;  USES: FSR1
73
;; --------------------------------------------------------------------------
74
MIOS_DIN_PinAutoRepeatEnable
75
	andlw	0x7f
76
	lfsr	FSR1, MIOS_DIN_REG0_00		; calc pointer to DIN register 00
77
	addwf	FSR1L, F
78
 
79
	bsf	INDF1, 7			; enable/disable handler
80
	bsf	MIOS_BOX_STAT, MIOS_BOX_STAT_AUTOREPEAT; enable the handler
81
	return
82
 
83
;; --------------------------------------------------------------------------
84
;;  FUNCTION: MIOS_DIN_PinAutoRepeatDisable
85
;;  C_DECLARATION: void MIOS_DIN_PinAutoRepeatDisable(unsigned char pin)
86
;;  DESCRIPTION: disables the auto-repeat feature for the appr. pin
87
;;  IN:	  number of pin in WREG
88
;;  C_IN: number of pin in <pin>
89
;;  OUT:  -
90
;;  C_OUT:  -
91
;;  USES: FSR1
92
;; --------------------------------------------------------------------------
93
MIOS_DIN_PinAutoRepeatDisable
94
	andlw	0x7f
95
	lfsr	FSR1, MIOS_DIN_REG0_00		; calc pointer to DIN register 00
96
	addwf	FSR1L, F
97
 
98
	bcf	INDF1, 7			; enable/disable handler
99
	;; ToDo: here we could disable the autorepeat-handler if this feature
100
	;; has been cleared for all buttons. However, it's difficult since
101
	;; also the encoder table has to be taken into account
102
	return
103
 
104
;; --------------------------------------------------------------------------
105
;;  FUNCTION: MIOS_DIN_PinAutoRepeatGet
106
;;  C_DECLARATION: unsigned char MIOS_DIN_PinAutoRepeatGet(unsigned char pin)
107
;;  DESCRIPTION: returns != 0 if auto-repeat has been enabled for the appr. pin
108
;;  IN:	  number of pin in WREG
109
;;  C_IN:  number of pin in <pin>
110
;;  OUT:  WREG != 0 if auto-repeat has been enabled for this pin
111
;;        WREG == 0 if auto-repeat has been disabled for this pin
112
;;  C_OUT:  != 0 if auto-repeat has been enabled for this pin
113
;;        0 if auto-repeat has been disabled for this pin
114
;;  USES: FSR1
115
;; --------------------------------------------------------------------------
116
MIOS_DIN_PinAutoRepeatGet
117
	andlw	0x0f
118
	lfsr	FSR1, MIOS_SR_DIN_0
119
	addwf	FSR1L, F
120
	movlw	0x00
121
	btfsc	INDF1, 7
122
	movlw	0x01
123
	movwf	MIOS_PARAMETER1
124
	return
125
 
126
;; --------------------------------------------------------------------------
127
;;  INTERNAL
128
;;  DESCRIPTION: returns value from two DIN Neighbour Pins
129
;;  IN:	  number of first Pin in WREG
130
;;  OUT:  0, 1, 2, 3
131
;;  USES: FSR1 and BSR
132
;; --------------------------------------------------------------------------
133
MIOS_DIN_2PinsGet
134
	andlw	0x7f
135
	lfsr	FSR1, MIOS_SR_DIN_0
136
	rgoto	MIOS_SRIO_Get2
137
 
138
;; --------------------------------------------------------------------------
139
;;  INTERNAL
140
;;  MIOS SRIO DIN CHANGED Set00: zeroes two neighboured DIN changed flags
141
;;  IN:	  number of first Pin in WREG
142
;;  OUT:  -
143
;;  USES: FSR1 and BSR
144
;; --------------------------------------------------------------------------
145
MIOS_DIN_ChangedSet00
146
	andlw	0x7e
147
	lfsr	FSR1, MIOS_SR_DIN_CHANGED_0
148
	rgoto	MIOS_SRIO_Set00
149
 
150
 
151
;; --------------------------------------------------------------------------
152
;;  MIOS DIN AutoRepeat Tick
153
;;  retriggers a pin if enabled
154
;; --------------------------------------------------------------------------
155
MIOS_DIN_AutoRepeat_Tick
156
	btfss	MIOS_BOX_STAT, MIOS_BOX_STAT_AUTOREPEAT
157
	return
158
 
159
	SET_BSR	MIOS_DIN_AUTO_CTR
160
	decfsz	MIOS_DIN_AUTO_CTR, F, BANKED
161
	return
162
 
163
	movlw	0x20
164
	movwf	MIOS_DIN_AUTO_CTR, BANKED
165
 
166
	movff	FSR0L, IRQ_TMP1			; store FSR0 in temp. register
167
	movff	FSR0H, IRQ_TMP2
168
	movff	FSR1L, MIOS_IRQ_FSR1L		; store FSR1 in temp. register
169
	movff	FSR1H, MIOS_IRQ_FSR1H
170
 
171
	lfsr	FSR0, MIOS_DIN_REG0_00
172
	lfsr	FSR1, MIOS_DIN_REG1_00
173
	lfsr	FSR2, MIOS_SR_DIN_0
174
 
175
MIOS_DIN_AutoRepeat_TickLoop
176
 
177
MIOS_DIN_AUTOREPEAT_TICK MACRO bit
178
	LOCAL	AR_Disabled
179
	LOCAL	AR_Next
180
	LOCAL	AR_Depressed
181
 
182
	BRA_IFCLR POSTINC0, 7, ACCESS, AR_Disabled
183
	BRA_IFSET INDF2, bit, ACCESS, AR_Depressed
184
	decfsz	INDF1, F
185
	rgoto	AR_Next
186
	incf	INDF1, F
187
	movlw	(MIOS_SR_DIN_CHANGED_0-MIOS_SR_DIN_0) & 0xff
188
	addwf	FSR2L, F
189
	bsf	INDF2, bit
190
	movlw	(MIOS_SR_DIN_0-MIOS_SR_DIN_CHANGED_0) & 0xff
191
	addwf	FSR2L, F
192
	rgoto	AR_Next
193
AR_Depressed
194
	movlw	0x10
195
	movwf	INDF1
196
	;; 	rgoto	AR_Next
197
AR_Next
198
AR_Disabled
199
	movf	POSTINC1, W	; (inc)
200
	ENDM
201
 
202
	MIOS_DIN_AUTOREPEAT_TICK 0
203
	MIOS_DIN_AUTOREPEAT_TICK 1
204
	MIOS_DIN_AUTOREPEAT_TICK 2
205
	MIOS_DIN_AUTOREPEAT_TICK 3
206
	MIOS_DIN_AUTOREPEAT_TICK 4
207
	MIOS_DIN_AUTOREPEAT_TICK 5
208
	MIOS_DIN_AUTOREPEAT_TICK 6
209
	MIOS_DIN_AUTOREPEAT_TICK 7
210
	movf	POSTINC2, W	; (inc)
211
 
212
MIOS_DIN_AutoRepeat_Tick_Next
213
	BRA_IFCLR FSR0L, 7, ACCESS, MIOS_DIN_AutoRepeat_TickLoop
214
 
215
	movff	MIOS_IRQ_FSR1L, FSR1L		; restore FSR1 from temp. register
216
	movff	MIOS_IRQ_FSR1H, FSR1H
217
	movff	IRQ_TMP1, FSR0L			; restore FSR0 from temp. register
218
	movff	IRQ_TMP2, FSR0H
219
	return
220
 
221
 
222
;; --------------------------------------------------------------------------
223
;;  MIOS DIN Handler
224
;;  check DIN_CHANGED flags, call USER_DIN_NotifyToggle when status of DIN
225
;;  pins have been changed
226
;; --------------------------------------------------------------------------
227
MIOS_DIN_Handler
228
	SET_BSR	MIOS_TMP_CTR
229
	clrf	MIOS_TMP_CTR, BANKED
230
MIOS_DIN_Handler_Loop
231
	lfsr	FSR0, MIOS_SR_DIN_CHANGED_0
232
	movf	MIOS_TMP_CTR, W, BANKED
233
	addwf	FSR0L, F
234
	movf	INDF0, W
235
	bz	MIOS_DIN_Handler_Loop_Next
236
	RCALL_IFSET INDF0, 0, ACCESS, MIOS_DIN_NotifyToggle_Pin0	; fastest solution...
237
	RCALL_IFSET INDF0, 1, ACCESS, MIOS_DIN_NotifyToggle_Pin1
238
	RCALL_IFSET INDF0, 2, ACCESS, MIOS_DIN_NotifyToggle_Pin2
239
	RCALL_IFSET INDF0, 3, ACCESS, MIOS_DIN_NotifyToggle_Pin3
240
	RCALL_IFSET INDF0, 4, ACCESS, MIOS_DIN_NotifyToggle_Pin4
241
	RCALL_IFSET INDF0, 5, ACCESS, MIOS_DIN_NotifyToggle_Pin5
242
	RCALL_IFSET INDF0, 6, ACCESS, MIOS_DIN_NotifyToggle_Pin6
243
	RCALL_IFSET INDF0, 7, ACCESS, MIOS_DIN_NotifyToggle_Pin7
244
MIOS_DIN_Handler_Loop_Next
245
	incf	MIOS_TMP_CTR, F, BANKED
246
	BRA_IFCLR MIOS_TMP_CTR, 4, BANKED, MIOS_DIN_Handler_Loop
247
 
248
	return
249
 
250
	;; ---
251
 
252
MIOS_DIN_NotifyToggle_Pin0
253
	bcf	INDF0, 0			; clear "changed" flag
254
	movlw	0x00 << 1
255
	rgoto	MIOS_DIN_NotifyToggle_Pin_Cont
256
MIOS_DIN_NotifyToggle_Pin1
257
	bcf	INDF0, 1			; clear "changed" flag
258
	movlw	0x01 << 1
259
	rgoto	MIOS_DIN_NotifyToggle_Pin_Cont
260
MIOS_DIN_NotifyToggle_Pin2
261
	bcf	INDF0, 2			; clear "changed" flag
262
	movlw	0x02 << 1
263
	rgoto	MIOS_DIN_NotifyToggle_Pin_Cont
264
MIOS_DIN_NotifyToggle_Pin3
265
	bcf	INDF0, 3			; clear "changed" flag
266
	movlw	0x03 << 1
267
	rgoto	MIOS_DIN_NotifyToggle_Pin_Cont
268
MIOS_DIN_NotifyToggle_Pin4
269
	bcf	INDF0, 4			; clear "changed" flag
270
	movlw	0x04 << 1
271
	rgoto	MIOS_DIN_NotifyToggle_Pin_Cont
272
MIOS_DIN_NotifyToggle_Pin5
273
	bcf	INDF0, 5			; clear "changed" flag
274
	movlw	0x05 << 1
275
	rgoto	MIOS_DIN_NotifyToggle_Pin_Cont
276
MIOS_DIN_NotifyToggle_Pin6
277
	bcf	INDF0, 6			; clear "changed" flag
278
	movlw	0x06 << 1
279
	rgoto	MIOS_DIN_NotifyToggle_Pin_Cont
280
MIOS_DIN_NotifyToggle_Pin7
281
	bcf	INDF0, 7			; clear "changed" flag
282
	movlw	0x07 << 1
283
	;; 	rgoto	MIOS_DIN_NotifyToggle_Pin_Cont
284
MIOS_DIN_NotifyToggle_Pin_Cont
285
	movwf	FSR0H				; use FSR0H as temp. register
286
	swapf	FSR0L, W			; calc DIN number
287
	andlw	0xf0
288
	iorwf	FSR0H, W
289
	clrc
290
	rrf	WREG, W
291
	movwf	MIOS_PARAMETER3
292
 
293
	rcall	MIOS_DIN_PinGet
294
	movwf	MIOS_PARAMETER2
295
 
296
	;; call hook
297
	movf	MIOS_PARAMETER3, W
298
	movwf	MIOS_PARAMETER1
299
	CALL_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_SUSPEND_USER, ACCESS, USER_DIN_NotifyToggle
300
 
301
	;; reload debounce counter
302
	movff	MIOS_SRIO_DEBOUNCE, MIOS_SRIO_DEBOUNCE_CTR
303
 
304
	lfsr	FSR0, MIOS_SR_DIN_CHANGED_0	; fix FSR0 if it has been overwritten
305
	SET_BSR	MIOS_TMP_CTR
306
	movf	MIOS_TMP_CTR, W, BANKED
307
	addwf	FSR0L, F
308
	return