From: Bdale Garbee Date: Fri, 21 Feb 2025 00:06:27 +0000 (-0700) Subject: start on i2c stuff X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=218a8a12b706eed985410dee5dc43936b23a09aa;p=fw%2Faltos start on i2c stuff --- diff --git a/src/lpc/ao_i2c_lpc.c b/src/lpc/ao_i2c_lpc.c new file mode 100644 index 00000000..48bf3cf3 --- /dev/null +++ b/src/lpc/ao_i2c_lpc.c @@ -0,0 +1,49 @@ +/* + * Copyright © 2025 Bdale Garbee + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +/* this I2C implementation written specifically to support the use of an + * LPC11U12 on QuantiMotor pretending to be an AD7997 ADC chip. So we're an + * I2C slave, with almost all the work done as an interrupt service routine. + */ + +#include + +static uint8_t ao_i2c_state; +static uint16_t ao_i2c_addr; + +static void +ao_i2c_isr() +{ + ao_wakeup(&ao_i2c_state); +} + +uint8_t +ao_i2c_start(uint16_t addr) +{ + ao_i2c_state = I2C_IDLE; + ao_i2c_addr = addr; + + ao_arch_block_interrupts(); + + /* set up I2C interrupt */ + /* wait for chip to go ready with some max wait? */ + + ao_arch_release_interrupts(); + return ao_i2c_state == I2C_RUNNING; +} + diff --git a/src/quantimotor-v2/Makefile b/src/quantimotor-v2/Makefile index c4fd6cba..937d4a38 100644 --- a/src/quantimotor-v2/Makefile +++ b/src/quantimotor-v2/Makefile @@ -34,7 +34,8 @@ ALTOS_SRC = \ ao_adc_lpc.c \ ao_serial_lpc.c \ ao_usb_lpc.c \ - ao_led.c + ao_led.c \ + ao_i2c_lpc.c PRODUCT=QuantiMotor-v2 PRODUCT_DEF=-DQUANTIMOTOR_V_2 diff --git a/src/quantimotor-v2/ao_pins.h b/src/quantimotor-v2/ao_pins.h index 5b4a6111..b56e429e 100644 --- a/src/quantimotor-v2/ao_pins.h +++ b/src/quantimotor-v2/ao_pins.h @@ -1,5 +1,5 @@ /* - * Copyright © 2024 Bdale Garbee * GPLv3 */