HDMI (DVI-D) and LCD display examples from previous versions have been updated for 080. The core of the display system consists of a board-specific library named (display hardware), that configures the hardware, and a main library named (display main), which enables writing text to the screen and doing low-level pixel drawing. These libraries are stored in files that should be placed on and SD-card, loaded onto the running MCU (to define the libraries) and the (display main) library should then be imported, prior to initializing the display. Considering the STM32F746G-Disco board as an example, the process would be:
(begin
(load "ds5STF74.scm")
(load "ds5_Main.scm")
(import (display main)))
(display-init) ; initialize display
After display initialization, the variable dsop contains the output port for the display (to be used for text output). Some examples of displaying text and drawing are (the font includes a few non-ASCII characters):
(display "hello world" dsop) ; display hello world
(newline dsop)
(write "èêîïçñ¿βγδε" dsop) ; show some font characters (unicode)
(line 50 50 150 75 #xff) ; draw a line
(fill 80 90 70 65 #xff00) ; draw a filled rectangle
The (display main) library is stored in file ds5_Main.scm with the ARMSchembly source of machine code functions in file ds5Msrc0.scm (when loaded into Armpit Scheme, this file automatically ARMSchembles the source code if the asT2, as32 and/or as64 ARMSchemblers are on the SD-card). The (display hardware) library files, for boards for which they are available, are given in Table 1.
BOARD | Library File |
SAMA5D4-Xplained-Ultra | ds5A5D4X.scm |
Beagle Bone Black | ds5BBB.scm |
Beagle XM rev C | ds5BBXM.scm |
Gumstix Duovero Crystal | ds5Duove.scm |
LPC4357-Xplorer | ds5LPC43.scm |
FriendlyARM NanoPC-T3 | ds5NaPC3.scm |
FriendlyARM NanoPC-T3+ | ds5NaPC3.scm |
MIMXRT1050-EVK | ds5RT105.scm |
STM32F429 Discovery | ds5STF42.scm |
STM32F746 Discovery | ds5STF74.scm |
A third library, named (display draw), is stored in file ds5Mgra3.scm. It contains scheme functions for drawing triangles and circles, and for performing color interpolation, based on a colormap or linearly, in lines and triangles. Examples of its use (after loading the file and importing the library) include:
(circlef 100 150 90 #xffff00)
(trianglef-li 10 140 #xff 110 60 #xff00 180 200 #xff0000)
A fourth (and last) library, named (display grid), is stored in file ds5Mdra3.scm. It contains scheme functions for drawing meshes and surfaces, possibly with shading. Examples of its use (after loading the file and importing the library) include:
;; surface 1
(begin
(define vxs #(0. 0. 0.))
(define vxe #(1. 1. 1.))
(define vnx #(11 11 1 ))
(define vwrap #(#f #f #f))
(define ncoords (nodecoords-on-grid vxs vxe vnx))
(vector-for-each (lambda (vxyz)
(let ((x (vector-ref vxyz 0))
(y (vector-ref vxyz 1)))
(vector-set! vxyz 2 (* y y))))
ncoords)
(cls)
(grid-draw6 ncoords vnx vwrap #f #f cmap64 #t #t #x808080 #t #f #t 30 -45)) ; tri surf, interp
;; surface 2
(let* ((vnx #(41 41 1))
(vxs #(0. 0. 0.))
(vxe (vector (* 2 pi) (* 2 pi) 1))
(vwrap #(#f #f #f))
(ncoords (nodecoords-on-grid vxs vxe vnx))
(fc (lambda (xyz) (let ((x (vector-ref xyz 0)) (y (vector-ref xyz 1)))
(if (even? (inexact->exact (+ (quotient x pi) (quotient y pi)))) #xff0000 #xffffff)))))
(vector-for-each
(lambda (vxyz)
(let ((x (vector-ref vxyz 0)) (y (vector-ref vxyz 1)))
(vector-set! vxyz 2 (* (exp (/ (- (* x y)) 10)) (sin x) (sin (* 2 y))))))
ncoords)
(cls)
(grid-draw6 ncoords vnx vwrap #f #f cmap64 #t #t #x808080 #t #f #t 30 -45)) ; tri surf, interp
;; torus
(let* ((nx 32) (ny 20)
(vnx (vector nx ny 1))
(vxs (vector (- pi) (- pi) 0.))
(vxe (vector (- pi (/ (* 2 pi) (- nx 1))) (- pi (/ (* 2 pi) (- ny 1))) 1.))
(vwrap #(#t #t #f))
(ncoords (vector-map
(lambda (vab)
(let ((a (vector-ref vab 0)) (b (vector-ref vab 1)))
(vector (* (+ 24 (* 4 (cos b))) (cos a))
(* (+ 24 (* 4 (cos b))) (sin a))
(* 4 (sin b)))))
(nodecoords-on-grid vxs vxe vnx)))
(fc (lambda (xyz) (let ((x (vector-ref xyz 0)) (y (vector-ref xyz 1)))
(if (even? (inexact->exact (truncate (/ (+ (atan y x) pi) (/ pi 8)))))
#xff0000 #xffffff)))))
(cls)
(grid-draw6 ncoords vnx vwrap #f #f #f #f #f #t fc '(#(0.577 0.577 -0.577) 0.15 #xffffff) #t 30 -45))
;; cylinder
(let* ((vnx (vector 15 20 9))
(vxs (vector 0. (- pi) 0.5))
(vxe (vector 3. (- pi (/ (* 2 pi) (- (vector-ref vnx 1) 1))) 1.0))
(vwrap #(#f #t #f))
(ncoords (vector-map
(lambda (xar)
(let ((x (vector-ref xar 0)) (a (vector-ref xar 1)) (r (vector-ref xar 2)))
(vector x (* r (sin a)) (* r (cos a)))))
(nodecoords-on-grid vxs vxe vnx)))
(cg (vector-map
(lambda (xyz) (let ((x (vector-ref xyz 0)))
(if (> x 2) #xff0000 (if (< x 1) #x4040ff #xffffff))))
ncoords)))
(cls)
(grid-draw6 ncoords vnx vwrap #f #f cg #f #f #f #f #f #t 30 -45)) ; tet mesh, user colors
; level surfaces in a rectangular prism
(let* ((vnx (vector 11 15 6))
(vxs (vector 0 0 0))
(vxe (vector 2 3 1))
(vwrap #(#f #f #f))
(ncoords (nodecoords-on-grid vxs vxe vnx))
(cg (vector-map
(lambda (xyz) (let ((y (vector-ref xyz 1)))
(if (> y 2) #xff (if (< y 1) #xff4040 #xffffff))))
ncoords))
(vvals (vector-map
(lambda (xyz) (let ((x (vector-ref xyz 0)) (y (vector-ref xyz 1)) (z (vector-ref xyz 2)))
(+ (* (- 2 x) (- 2 x)) (* y y) (* (- 1 z) (- 1 z)))))
ncoords)))
(cls)
(grid-draw6 ncoords vnx vwrap vvals #(1.0 3.0 6.0 9.0 12.0) cmap64 #f #f #t #f
'(#(0. 1. 0.) 0.15 #x00) #t 30 -45))
This version of Armpit Scheme is the first for which USB-Host code has been developed, and this code is aimed at processing input from a USB keyboard which a user may connect to the board. The USB keyboard system consists of a board-specific library named (usb-host hardware), that configures the hardware and may include an MCU-specific ISR, and a main library named (usb-host main), which enables the USB Host system, performs enumeration (looking for a keyboard) and sets things up such that the keyboard can serve as input-port, with an arbitrary echo port (eg. a uart/USB-device or an LCD/DVI-D display). These libraries are stored in files that should be placed on and SD-card, loaded onto the running MCU (to define the libraries) and the (usb-host main) library should then be imported, prior to initializing the usb-host and keyboard. Considering the STM32F746G-Disco board as an example, the process would be (the keyboard should be plugged into the board already):
(begin
(load "uh5STF74.scm") ; load hardware library from SD-card
(load "uh5Main1.scm") ; load main library from SD-card
(import (usb-host main))) ; import the main library
(begin
(init-usb-host) ; initialize usb-host
(init-keyboard)) ; initialize keyboard
The (usb-host main) library is stored in file uh5Main1.scm with the ARMSchembly source of machine code functions in file uh5Msrc1.scm (when loaded into Armpit Scheme, this file automatically ARMSchembles the source code if the asT2, as32 and/or as64 ARMSchemblers are on the SD-card). The (usb-host hardware) library files, for boards for which they are available, are given in Table 2.
BOARD | Library File |
SAMA5D4-Xplained-Ultra | uh5A5D4X.scm |
Beagle Bone Black | uh5BBB.scm |
Beagle XM rev C | uh5BBXM.scm |
Gumstix Duovero Crystal | uh5Duove.scm |
LPC4357-Xplorer | uh5LPC43.scm |
FriendlyARM NanoPC-T3 | uh5NaPC3.scm |
FriendlyARM NanoPC-T3+ | uh5NaPCP.scm |
STM32F746 Discovery | uh5STF74.scm |