2 @(define ports '(P0 P1 P2 P3 P4))
3 @(define registers '(LPC_GPIO0 LPC_GPIO1 LPC_GPIO2 LPC_GPIO3 LPC_GPIO4))
5 * IO functions for NXP LPC1768. (generated file, check io-pin.ss)
7 * See also: http://bitbucket.org/jpc/lpc1768/
9 * Copyright (c) 2010 LoEE - Jakub Piotr Cłapa
10 * This program is released under the new BSD license.
15 #include "CMSIS/LPC17xx.h"
19 (for/list ([i (in-naturals)]
21 @list{@port = @(* i 32),}))
29 extern void invalid_pin_error () __attribute__((error ("Invalid IO pin number.")));
31 @(define INLINE "extern __inline__ __attribute__((always_inline))")
32 @(define-syntax-rule (switch pin_no i register template)
33 @list{switch(pin_no) {
35 (for/list ([i (in-naturals)]
37 @list{case @(* i 32) ... @(sub1 (* (add1 i) 32)):
45 int pin_read (int pin_no)
47 @(switch @{pin_no} i register
48 @list{return @|register|->FIOPIN & (1 << (pin_no - @(* i 32)));})
53 void pin_write (int pin_no, int value)
55 @(switch @{pin_no} i register
57 @|register|->FIOSET = (1 << (pin_no - @(* i 32)));
59 @|register|->FIOCLR = (1 << (pin_no - @(* i 32)));
65 void pin_dir (int pin_no, enum pin_dir dir)
67 @(switch @{pin_no} i register
68 @list{if (dir == PIN_OUT) {
69 @|register|->FIODIR @"|=" (1 << (pin_no - @(* i 32)));
71 @|register|->FIODIR @"&=" (1 << (pin_no - @(* i 32)));