(theoretically) got encoders working
Everything up to sending all 8 encoder values should work now (including
the packet format + header information, bootloader (fixed some bugs in
the UART code for that), etc).
diff --git a/bbb_cape/src/cape/util.h b/bbb_cape/src/cape/util.h
index dac30d5..b27cc77 100644
--- a/bbb_cape/src/cape/util.h
+++ b/bbb_cape/src/cape/util.h
@@ -1,6 +1,8 @@
#ifndef CAPE_UTIL_H_
#define CAPE_UTIL_H_
+#include <STM32F2XX.h>
+
#define ALIAS_WEAK(f) __attribute__ ((weak, alias (#f)))
// MSG has to be separated_with_spaces.
@@ -11,4 +13,26 @@
__asm__ __volatile__("" ::: "memory");
}
+// Sets number_of_bits (shifted left shift number of slots) to value in
+// variable.
+// This means that the total shift is number_bits*shift.
+#define SET_BITS(variable, number_bits, value, shift) do { \
+ variable = (((variable) & \
+ ~(((1 << (number_bits)) - 1) << (shift * (number_bits)))) | \
+ ((value) << (shift * (number_bits)))); \
+} while (0);
+
+// A convenient way to set up a GPIO pin for some alternate function without
+// missing part or messing up which bits need setting to what.
+// pin is the 0-indexed pin number.
+// afr is 0-0xF for the various alternate functions.
+static inline void gpio_setup_alt(GPIO_TypeDef *port, int pin, int afr) {
+ SET_BITS(port->MODER, 2, 2 /* alternate function */, pin);
+ if (pin < 8) {
+ SET_BITS(port->AFR[0], 4, afr, pin);
+ } else {
+ SET_BITS(port->AFR[1], 4, afr, (pin - 8));
+ }
+}
+
#endif // CAPE_UTIL_H_