The LED and Thread example for this release is identical to that of version 050, with updates discussed in version 060, for most MCUs. New differences are as follows: 1) the LED ports and pins for the new MCUs (please consult board.h source files for more) are:
;----------------------------------------------------------
; cortex-m4 microcontroller boards
;----------------------------------------------------------
; LPC4357-Xplorer
(begin
(define ledport gio4) ; GPIO PORT 4
(define ledpin1 11)) ; red led
;----------------------------------------------------------
; cortex-a8 application processor boards
;----------------------------------------------------------
; TI-BeagleBoneBlack
(begin
(define ledport gio1) ; GPIO PORT 1
(define ledpin1 21) ; USER blue led 0
(define ledpin2 22) ; USER blue led 1
(define ledpin3 23)) ; USER blue led 2
;----------------------------------------------------------
; cortex-a9 application processor boards
;----------------------------------------------------------
; Gumstix Duovero Crystal on Parlor (OMAP4430)
(begin
(define ledport gio4) ; GPIO PORT 4
(define ledpin1 26)) ; Parlor blue led
2) and, for the new Cortex-A8 and A9 MCUs:
;----------------------------------------------------------
; cortex-a8 application processors
;----------------------------------------------------------
; TI-BeagleBoneBlack (AM335x)
; define ports and offsets, functions to stop, start timer, and configure timer
(begin
(define mt-timer tmr1) ; DMTimer2 base address (aliased to tmr1)
(define mt-timer-int 68) ; DMTimer2 interrupt (bit) number
(define timer-count #x3c)
(stop mt-timer)
(write #x04 mt-timer #x10) ; config
(write 133333 mt-timer #x4c) ; period
(write #x01 mt-timer #x2c)) ; interrupt
;----------------------------------------------------------
; cortex-a9 application processors
;----------------------------------------------------------
; Gumstix Duovero Crystal (OMAP4430)
; define ports and offsets, functions to stop, start timer, and configure timer
(begin
(define mt-timer (if (= 0 (cpu-id)) tmr1 tmr2)) ; GPTimer1 or 2 base address
(define mt-timer-int (if (= 0 (cpu-id)) 37 38)) ; GPTimer1 or 2 interrupt number
(define timer-count #x28)
(stop mt-timer)
(write #x08 mt-timer #x10) ; config
(write 133333 mt-timer #x38) ; period
(write #x01 mt-timer #x1c)) ; interrupt
The ADC and PWM examples from version 050 (no changes in 060) are expected to work unmodified but have not been tested in 070 as of yet. For the Freescale FRDM-K64F board, the ADC code below is provided as an example:
;===============================================================================
;
; XII. ADC on Freescale FRDM-K64F
;
;===============================================================================
;----------------------------------------------------------
; Part 1: ADC (p. 316, p. 825+)
;----------------------------------------------------------
; function to power-up adc (adc0 or adc1), set speed and mode (12-bit, 0-4096)
(define (config-adc adc)
(config-power (if (eq? adc adc0) 6 3) 27 1) ; ADC0/1 bit 27 in SCGC6/3 (p.316)
(write #x64 adc #x08) ; ADCx_CFG1 <- set ADIV = 60MHz/8, MODE = 12-bit
(write #x04 adc #x0c)) ; ADCx_CFG2 <- set ADHSC bit: high-speed (clock) mode
; function to read adc channel
(define (read-adc adc chan)
(write chan adc #x00) ; ADCx_SC1A <- start conversion, single-ended
(let loop ((stat 0))
(if (bitwise-bit-set? stat 7) ; ADCx_SC1A COCO bit set?
(read adc #x10) ; if so, return result = ADCx_RA
(loop (read adc #x00))))) ; get status = ADCx_SC1A and loop back
; initialize adc
(config-adc adc0)
; read ADC0_DP1 (pin is pre-configured - no mux needed in config)
(read-adc adc0 1)
LCD examples (from 050) have been updated for this version and to inlcude new boards and line drawing:
ap> (load "lcdIDM35.scm" SDFT) ; for IDM-L35 (16-bit color) OR: ap> (load "lcdSTM32.scm" SDFT) ; for STM32-LCD (16-bit color) OR: ap> (load "lcdDisco.scm" SDFT) ; for STM32F429-Discovery (24-bit color) OR: ap> (load "lcdLPC24.scm" SDFT) ; for LPC2478-STK (24-bit color) OR: ap> (load "lcdLPC43.scm" SDFT) ; for LPC4357-Xplorer (24-bit color) AND: ap> (libs) ; check for presence of (lcd output)After installation, the libraries can be imported, initialized and tested. The libraries offer similar functionality, except for the different number of color bits. As with other libraries, configuration (lcd-config) should be performed only once, but initialization (lcd-init) may be performed multiple times. The following example illustrates (adapted from prior snapshots, for library operation):
ap> (import (lcd output)) ; import the library ap> (lcd-config) ; configure LCD pins and lcop ap> (lcd-init) ; initialize the LCD ap> (display "HELLO!" lcop) ap> (fill 50 50 150 150 #xff) ap> (line 150 150 175 210 #xff) ap> (define ocop (current-output-port)) ; save the current output-port ap> (define (current-output-port) lcop) ; set default output to LCD ap> 100 ap> "WOWEE!"
A new library (in scheme) uses the primitives in the above libraries to draw shapes: triangles, filled triangles, circles, filled circles, lines with color interpolation, triangles with interpolated edge color and triangles with interpolated fill color (note: all color interpolations are form a color map). This library comes in 2 versions: regular for most MCUs, and, fx-less for MCUs without FixNum functions (eg. fx+) like the LPC4357-Xplorer++ DFU version (the FLASH version has FixNum functions). Comments at the top of the library file indicate expected usage.
Updates of the touchscreen and accelerometer examples from version 050 are as follows:
Code examples of basic DVI-D (HDMI connector) output to a TV, for the TI Cortex-A8 and Cortex-A9 boards, are given below. The code enables syncing with a North-American TV (60Hz) at a resolution between 640x480 and 1920x1080 (board-dependent), and also allows colored horizontal and vertical lines to be drawn on the TV. It does not read EDID or send sound to the TV. The code is not particularly fast (eg. (cls) takes 3 seconds) as it is scheme-only (no ARMSchembly version yet). The TV on which this was tested is an RCA model LED24B45RQ.
The DFU version of the LPC4357-Xplorer code in ArmPit Scheme 070 is a small memory version that, while it uses 32MB of external RAM, does not include macros, r5rs library functions and non-integers (the reason is the small boot RAM available for DFU on this MCU). The code was however designed to allow importing the regular numbers library into a running system (should be done way at the start of interactions), and it is straightforward to load a standard set of macros and an r5rs library, both written in scheme, from file (eg. on SD card), to expand the system's capabilities. The build_all_aps script builds a scheme bytevector that contains the regular numbers library and stores it in the aps_bin folder in a file named: LPC4357Xplorer_lib_numbers_aps_070_bin.scm. This file should be copied to an SD card an renamed numbers.scm for upload into the running system. If these files (numbers, macros and lib_r5rs) are on an SD card, and the card has been initialized with (sd-init), then the following sequence of commands should bring the system to regular status:
((lambda (p) (bnld (read p)) (close-input-port p)) (open-input-file "numbers.scm" SDFT))
(load "macros.scm" SDFT)
(load "lib_r5rs.scm" SDFT)
(import (macros) (r5rs))
ArmPit Scheme code for the Duovero Crystal in version 070 is a regular version except for its lack of floats, rationals and complex numbers. These regular numbers were removed because the boot RAM of the OMAP4430 is 48 KB in size which is too small for a complete system. The build_all_aps script however builds a scheme bytevector that contains the regular numbers library and stores it in the aps_bin folder in a file named: DuoveroCrystal_lib_numbers_aps_070_bin.scm. This file can be (binary-) loaded into a running system (should be done way at the start of interactions), to install non-integer functionality. The suggested approach is to copy DuoveroCrystal_lib_numbers_aps_070_bin.scm to an SD card and rename it: numbers.scm. Then, insert the card in the Duovero Crystal and execute (separately on each core):
(let ((p (open-input-file "numbers.scm")))
(bnld (read p))
(close-input-port p))
Cores are identified by the function cpu-id:
(cpu-id) ;; returns 0 or 1 based on core on which it is running