Permalink
Browse files

cortex: digital and interrupt fixups.

  • Loading branch information...
1 parent bf04e8b commit 3d49903ebd9b94316d7119ba688f2ed3f6251341 @jmesmon jmesmon committed Jan 14, 2011
Showing with 40 additions and 29 deletions.
  1. +32 −25 arch_cortex/exti.c
  2. +1 −1 arch_cortex/gcc.mk
  3. +0 −3 build.mk
  4. +7 −0 test/user.c
View
@@ -27,10 +27,13 @@ static const uint8_t pin_to_ifipin [16] =
static isr_t isr_callback[12];
+#define DIG_VALID(pin) (pin < CT_DIGITAL)
+#define INT_VALID(pin) (DIG_VALID(pin) && (pin != 9))
+
/* HAX interrupt code */
void interrupt_reg_isr(index_t index, isr_t isr) {
index_t pin = index - IX_DIGITAL(1);
- if (!(0 <= pin && pin <= 11 && pin != 9)) {
+ if (!INT_VALID(pin)) {
WARN_IX(index);
return;
}
@@ -40,7 +43,7 @@ void interrupt_reg_isr(index_t index, isr_t isr) {
void interrupt_setup(index_t index, isr_t isr)
{
index_t pin = index - IX_DIGITAL(1);
- if (!(0 <= pin && pin <= 11 && pin != 9)) {
+ if (!INT_VALID(pin)) {
WARN_IX(index);
return;
}
@@ -54,7 +57,7 @@ void interrupt_setup(index_t index, isr_t isr)
void interrupt_set(index_t index, bool enable)
{
index_t pin = index - IX_DIGITAL(1);
- if (!(0 <= pin && pin <= 11 && pin != 9)) {
+ if (!INT_VALID(pin)) {
WARN_IX(index);
return;
}
@@ -70,45 +73,49 @@ void interrupt_set(index_t index, bool enable)
/* HAX digital io api */
void digital_setup(index_t index, bool output)
{
- /* Only external digital pins can be used as output. */
- if (IX_DIGITAL(1) <= index && index <= IX_DIGITAL(CT_DIGITAL)) {
+ index_t pin = index - IX_DIGITAL(1);
+ if (!DIG_VALID(pin)) {
WARN_IX(index);
+ return
+ }
+
+ GPIO_InitTypeDef param;
+ param.GPIO_Pin = 1 << ifipin_to_pin[pin];
+ if (output) {
+ param.GPIO_Mode = GPIO_Mode_IPU;
+ param.GPIO_Speed = GPIO_Speed_50MHz;
} else {
- GPIO_InitTypeDef param;
- param.GPIO_Pin = 1 << ifipin_to_pin[index - 1];
- if (output) {
- param.GPIO_Mode = GPIO_Mode_IPU;
- param.GPIO_Speed = GPIO_Speed_50MHz;
- } else {
- param.GPIO_Mode = GPIO_Mode_Out_PP;
- }
- GPIO_Init((GPIO_TypeDef *)ifipin_to_port[index - 1], &param);
+ param.GPIO_Mode = GPIO_Mode_Out_PP;
}
+ GPIO_Init((GPIO_TypeDef *)ifipin_to_port[pin], &param);
}
bool digital_get(index_t index)
{
- if (IX_DIGITAL(1) <= index && index <= IX_DIGITAL(CT_DIGITAL)) {
- GPIO_TypeDef * port = ifipin_to_port[index - OFFSET_DIGITAL - 1];
- index_t pin = ifipin_to_pin[index - OFFSET_DIGITAL - 1];
- return !!(port->IDR & (1 << pin));
- } else {
+ index_t pin = index - IX_DIGITAL(1);
+ if (!DIG_VALID(pin)) {
WARN_IX(index);
return false;
}
+
+ GPIO_TypeDef * port = ifipin_to_port[pin];
+ index_t rpin = ifipin_to_pin[pin];
+ return !!(port->IDR & (1 << rpin));
}
void digital_set(index_t index, bool output)
{
- index_t pin = index - OFFSET_DIGITAL;
+ index_t pin = index - IX_DIGITAL(1);
- // Only external digital pins can be used as output.
- if (index < OFFSET_DIGITAL || index >= OFFSET_DIGITAL + CT_DIGITAL) {
+ if (!DIG_VALID(pin)) {
WARN_IX(index);
- } else if (output) {
- ifipin_to_port[index]->BSRR = 1 << ifipin_to_pin[pin];
+ return;
+ }
+
+ if (output) {
+ ifipin_to_port[pin]->BSRR = 1 << ifipin_to_pin[pin];
} else {
- ifipin_to_port[index]->BRR = 1 << ifipin_to_pin[pin];
+ ifipin_to_port[pin]->BRR = 1 << ifipin_to_pin[pin];
}
}
View
@@ -25,7 +25,7 @@ ARCH_CFLAGS= -D$(STMPROC) -DHSE_VALUE=$(HSE_VALUE) \
-Wno-main -DUSE_STDPERIPH_DRIVER -pipe \
-ffunction-sections -fno-unwind-tables \
-D_SMALL_PRINTF -DNO_FLOATING_POINT \
- -Os \
+ -Os -Wextra \
-ggdb -DARCH_CORTEX $(CC_INC) $(CFLAGS)
ARCH_LDFLAGS=$(ALL_CFLAGS) \
View
@@ -19,9 +19,6 @@ ifndef prog
$(error "unnamed program")
endif
-ifeq ($(serial),)
-$(warning "no serial port specified; 'make install' may fail")
-endif
.SUFFIXES:
.PHONY: all clean build rebuild install
View
@@ -1,6 +1,7 @@
#include <hax.h>
#include <stdbool.h>
#include <stdint.h>
+#include <stdio.h>
#include "user.h"
@@ -51,6 +52,12 @@ void telop_loop(void) {
int8_t left = oi_group_get(IX_OI_GROUP(1, 3));
int8_t right = oi_group_get(IX_OI_GROUP(1, 2));
+ printf("left: %d, right: %d", left, right);
+
+ bool oi_thing = oi_button_get(IX_OI_BUTTON(1, 7, OI_B_UP));
+
+ motor_set(IX_MOTOR(4), 127*oi_thing);
+
motor_set(IX_MOTOR(2), left);
motor_set(IX_MOTOR(3), -right);
}

0 comments on commit 3d49903

Please sign in to comment.