Skip to content

Instantly share code, notes, and snippets.

View tcdowney's full-sized avatar

Tim Downey tcdowney

View GitHub Profile
void ds_gyro_read(uint8_t* pBuffer, uint8_t ReadAddr, volatile uint16_t NumByteToRead) {
if (NumByteToRead > 0x01) {
ReadAddr |= (uint8_t)(0x80 | 0x40); // If sending more that one byte set multibyte commands
}
else {
ReadAddr |= (uint8_t) (0x80); // Else just set the read mode
}
GYRO_CS_LOW();
//GPIO_ResetBits(GPIOE, GPIO_Pin_3);
@tcdowney
tcdowney / free?.scm
Created January 21, 2013 02:12
Scheme snippet that returns true if the variable is a free variable in the expression. Taken from C311 notes and uses pmatch library.
(define free?
(lambda (y e ce)
(pmatch e
[,x (guard (symbol? x)) (and (eq? x y) (not (memq y ce)))]
[(lambda (,x) ,body) (free? y body (cons x ce))]
[(,rator ,rand) (or (free? y rator ce)(free? y rand ce))])))
@tcdowney
tcdowney / member?.scm
Created January 9, 2013 18:10
The definition for member? for The Little Schemer. Returns #t if the first argument (an atom) is found in the second argument (a list of atoms).
(define member?
(lambda (a lat)
(cond
((null? lat) #f)
(else (or (eq? (car lat) a) (member? a (cdr lat)))))))
@tcdowney
tcdowney / lat?.scm
Created January 9, 2013 15:58
Definition for lat? for The Little Schemer. #myversion
;; A lat is a list of atoms.
(define lat?
(lambda (l)
(cond
((null? l) #t)
((not (atom? (car l))) #f)
(else (lat? (cdr l))))))
@tcdowney
tcdowney / atom?.ss
Created January 8, 2013 16:28
Definition for atom? for The Little Schemer.
(define atom?
(lambda (x)
(and (not (pair? x)) (not (null? x)))))
;; Test code
(atom? (quote ()))