Subversion Repositories Kolibri OS

Rev

Rev 5558 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5558 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;                                                  ;
3
;    86DUINO GPIO DEMO APPLICATION                 ;
4
;                                                  ;
5
;      Compile with FASM                           ;
6
;                                                  ;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
 
9
format binary as ""                     ; Binary file format without extension
10
 
11
use32                                   ; Tell compiler to use 32 bit instructions
12
 
13
org 0x0                                 ; the base address of code, always 0x0
14
 
15
; The header
16
 
17
db 'MENUET01'
18
dd 0x01
19
dd START
20
dd I_END
21
dd 0x100000
22
dd 0x7fff0
23
dd 0, 0
24
 
25
; The code area
26
 
27
include '../../macros.inc'
28
 
29
START:                                  ; start of execution
30
 
31
        mcall   68, 16, drv_name        ; load the driver
32
        mov     [IOCTL.handle], eax
33
 
34
        call    draw_window             ; draw the window
35
 
36
; After the window is drawn, it's practical to have the main loop.
37
; Events are distributed from here.
38
 
39
event_wait:
40
        mov     eax, 10                 ; function 10 : wait until event
41
        mcall                           ; event type is returned in eax
42
 
43
        cmp     eax, 1                  ; Event redraw request ?
44
        je      red                     ; Expl.: there has been activity on screen and
45
                                        ; parts of the applications has to be redrawn.
46
 
47
        cmp     eax, 2                  ; Event key in buffer ?
48
        je      key                     ; Expl.: User has pressed a key while the
49
                                        ; app is at the top of the window stack.
50
 
51
        cmp     eax, 3                  ; Event button in buffer ?
52
        je      button                  ; Expl.: User has pressed one of the
53
                                        ; applications buttons.
54
 
55
        jmp     event_wait
56
 
57
;  The next section reads the event and processes data.
58
 
59
red:                                    ; Redraw event handler
60
        call    draw_window             ; We call the window_draw function and
61
        jmp     event_wait              ; jump back to event_wait
62
 
63
key:                                    ; Keypress event handler
64
        mov     eax, 2                  ; The key is returned in ah. The key must be
65
        mcall                           ; read and cleared from the system queue.
66
 
67
        cmp     ah, 'q'
68
        jne     @f
69
        call    read_gpio0
70
        or      al, 1                   ; Set bit 0
71
        call    write_gpio0
72
        jmp     event_wait
73
  @@:
74
        cmp     ah, 'w'
75
        jne     @f
76
        call    read_gpio0
77
        and     al, not 1               ; Clear bit 0
78
        call    write_gpio0
79
        jmp     event_wait
80
  @@:
6878 hidnplayr 81
        cmp     ah, 'e'
82
        jne     @f
83
        call    read_adc0
84
        mov     ecx, eax
85
        mcall   47, 0x00040100,,25 shl 16 + 25, 0x40000000, 0x00ffffff          ; 4 digits hex number in ecx
86
        jmp     event_wait
87
  @@:
5558 hidnplayr 88
        jmp     event_wait              ; Just read the key, ignore it and jump to event_wait.
89
 
90
button:                                 ; Buttonpress event handler
91
        mov     eax,17                  ; The button number defined in window_draw
92
        mcall                           ; is returned to ah.
93
 
94
        cmp     ah,1                    ; button id=1 ?
95
        jne     noclose
96
        mov     eax,-1                  ; Function -1 : close this program
97
        mcall
98
 
99
noclose:
100
        jmp     event_wait              ; This is for ignored events, useful at development
101
 
102
;  *********************************************
103
;  ******  WINDOW DEFINITIONS AND DRAW  ********
104
;  *********************************************
105
;
106
;  The static window parts are drawn in this function. The window canvas can
107
;  be accessed later from any parts of this code (thread) for displaying
108
;  processes or recorded data, for example.
109
;
110
;  The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.
111
 
112
draw_window:
113
        mov     eax, 12                 ; function 12: tell os about windowdraw
114
        mov     ebx, 1                  ; 1, start of draw
115
        mcall
116
 
117
        mov     eax, 0                  ; function 0 : define and draw window
118
        mov     ebx, 100 * 65536 + 300  ; [x start] *65536 + [x size]
119
        mov     ecx, 100 * 65536 + 120  ; [y start] *65536 + [y size]
120
        mov     edx, 0x14ffffff         ; color of work area RRGGBB
121
                                        ; 0x02000000 = window type 4 (fixed size, skinned window)
122
        mov     esi, 0x808899ff         ; color of grab bar  RRGGBB
123
                                        ; 0x80000000 = color glide
124
        mov     edi, title
125
        mcall
126
 
127
        mov     ebx, 25 * 65536 + 35    ; draw info text with function 4
128
        mov     ecx, 0x224466
129
        mov     edx, text
130
        mov     esi, 40
131
        mov     eax, 4
132
 
133
  .newline:                             ; text from the DATA AREA
134
        mcall
135
        add     ebx, 10
136
        add     edx, 40
137
        cmp     byte[edx], 0
138
        jne     .newline
139
 
140
        mov     eax, 12                 ; function 12:tell os about windowdraw
141
        mov     ebx, 2                  ; 2, end of draw
142
        mcall
143
 
144
        ret
145
 
146
; Read GPIO0 port to AL register
147
read_gpio0:
148
        mov     [IOCTL.io_code], 1
149
        mcall   68, 17, IOCTL
150
        ret
151
 
152
; Write AL register to GPIO0 port
153
write_gpio0:
154
        mov     [IOCTL.io_code], 2
155
        mov     [IOCTL.input], eax
156
        mcall   68, 17, IOCTL
157
        ret
6878 hidnplayr 158
 
159
; Read ADC0
160
read_adc0:
161
        mov     [IOCTL.io_code], 3
162
        mcall   68, 17, IOCTL
163
        ret
5558 hidnplayr 164
 
165
;  *********************************************
166
;  *************   DATA AREA   *****************
167
;  *********************************************
168
;
169
; Data can be freely mixed with code to any parts of the image.
170
; Only the header information is required at the beginning of the image.
171
 
172
text    db  "This is an 86DUINO GPIO demo program    "
173
        db  "                                        "
6878 hidnplayr 174
        db  "press q/w to toggle GPIO 0 pin 0        "
175
        db  "or e to read ADC0 channel               ", 0
5558 hidnplayr 176
 
177
title   db  "86Duino Example application", 0
178
 
179
drv_name        db '86DUINO-GPIO', 0
180
 
181
IOCTL:
182
   .handle      dd ?
183
   .io_code     dd ?
184
   .input       dd ?
185
   .inp_size    dd ?
186
   .output      dd ?
187
   .out_size    dd ?
188
 
189
I_END: