adding more lisp tools
This commit is contained in:
parent
101f0b998f
commit
3d3b27baad
|
@ -0,0 +1,43 @@
|
||||||
|
(defvar *rtc-port* 0)
|
||||||
|
|
||||||
|
(defun rtc-set (hr min)
|
||||||
|
"(rtc-set hr min)
|
||||||
|
Set the time on a DS3231 RTC. Times are in BCD, so use
|
||||||
|
the appropriate reader macro, e.g. (rtc-set #x12 #x34)
|
||||||
|
for 12:34. Assumes seconds are zero."
|
||||||
|
(with-i2c (str *rtc-port* #x68)
|
||||||
|
(write-byte 0 str)
|
||||||
|
(write-byte 0 str)
|
||||||
|
(write-byte min str)
|
||||||
|
(write-byte hr str)))
|
||||||
|
|
||||||
|
(defun bcd-to-dec (x)
|
||||||
|
"(bcd-to-dec x)
|
||||||
|
Convert the BCD-encoded number x to a decimal value."
|
||||||
|
(+
|
||||||
|
(* 10 (ash x -4))
|
||||||
|
(logand x #xf)))
|
||||||
|
|
||||||
|
(defun dec-to-bcd (x)
|
||||||
|
"(dec-to-bcd x)
|
||||||
|
Converts the decimal value to a BCD-encoded number.
|
||||||
|
Number must be in the range 0 to 99.")
|
||||||
|
|
||||||
|
(defun rtc-get ()
|
||||||
|
(with-i2c (str *rtc-port* #x68)
|
||||||
|
(write-byte 0 str)
|
||||||
|
(restart-i2c str 3)
|
||||||
|
(mapcar bcd-to-dec
|
||||||
|
(reverse
|
||||||
|
(list
|
||||||
|
(read-byte str)
|
||||||
|
(read-byte str)
|
||||||
|
(read-byte str))))))
|
||||||
|
|
||||||
|
(defun rtc-now ()
|
||||||
|
"(rtc-now)
|
||||||
|
Set the time using the RTC."
|
||||||
|
(apply now (rtc-get)))
|
||||||
|
|
||||||
|
(defun now-rtc ()
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
MEDIA="$1"
|
||||||
|
cp *.lsp "$MEDIA"
|
||||||
|
umount "$MEDIA"
|
|
@ -0,0 +1,30 @@
|
||||||
|
(defun pprintf (sym str)
|
||||||
|
"(pprintf sym str)
|
||||||
|
Pretty-print the function pointed to by sym to
|
||||||
|
the stream, which follows the 'format directives."
|
||||||
|
(let ((form (eval sym)))
|
||||||
|
(format str "(defun ~a ~a~%~{ ~a~^~%~})"
|
||||||
|
(string sym)
|
||||||
|
(cadr form)
|
||||||
|
(cddr form))))
|
||||||
|
|
||||||
|
(defun copy-file (source dest)
|
||||||
|
(with-sd-card (writer dest 2)
|
||||||
|
(with-sd-card (reader source)
|
||||||
|
(loop
|
||||||
|
(let ((data (read-byte reader)))
|
||||||
|
(when (null data)
|
||||||
|
(return))
|
||||||
|
(write-byte data writer))))))
|
||||||
|
|
||||||
|
(defun i2c-scan (port)
|
||||||
|
(dotimes (addr 127)
|
||||||
|
(with-i2c (str port addr)
|
||||||
|
(when str (print addr)))))
|
||||||
|
|
||||||
|
(defun i2c-scan2 (port)
|
||||||
|
(dotimes (addr 127)
|
||||||
|
(with-i2c (str port addr)
|
||||||
|
(format t "~2,0'x: " addr)
|
||||||
|
(if str (print t)
|
||||||
|
(print nil)))))
|
Loading…
Reference in New Issue