summaryrefslogtreecommitdiff
path: root/digital/dev2/src/usb_serial_isp
diff options
context:
space:
mode:
authorNicolas Schodet2009-04-25 13:25:15 +0200
committerNicolas Schodet2009-04-25 13:25:15 +0200
commitfe9885ff7bd10dd19292bbe42879004b86b9ba08 (patch)
treea765bd67c12b2a40c831350c6a10963573cbcd14 /digital/dev2/src/usb_serial_isp
parent00ba3a7f13e2d6c5688d96c73d9012859e8a6350 (diff)
* digital/dev2:
- added real ISP.
Diffstat (limited to 'digital/dev2/src/usb_serial_isp')
-rw-r--r--digital/dev2/src/usb_serial_isp/Makefile4
-rw-r--r--digital/dev2/src/usb_serial_isp/avrconfig.h40
-rw-r--r--digital/dev2/src/usb_serial_isp/main.c44
3 files changed, 42 insertions, 46 deletions
diff --git a/digital/dev2/src/usb_serial_isp/Makefile b/digital/dev2/src/usb_serial_isp/Makefile
index d2124ae1..6034b9b0 100644
--- a/digital/dev2/src/usb_serial_isp/Makefile
+++ b/digital/dev2/src/usb_serial_isp/Makefile
@@ -1,7 +1,7 @@
BASE = ../../../avr
AVR_PROGS = dev2_serial_isp
-dev2_serial_isp_SOURCES = main.c descriptors.c serial.c select.c
-MODULES = usb uart isp
+dev2_serial_isp_SOURCES = main.c descriptors.c serial.c select.c usb_isp.c
+MODULES = usb uart isp spi
CONFIGFILE = avrconfig.h
AVR_MCU = at90usb162
# -O2 : speed
diff --git a/digital/dev2/src/usb_serial_isp/avrconfig.h b/digital/dev2/src/usb_serial_isp/avrconfig.h
index 37b1b21e..1dfd63d2 100644
--- a/digital/dev2/src/usb_serial_isp/avrconfig.h
+++ b/digital/dev2/src/usb_serial_isp/avrconfig.h
@@ -73,15 +73,51 @@
#define AC_UART1_SEND_BUFFER_FULL WAIT
#define AC_UART1_HOST_DRIVER PTS
+/* spi - SPI module. */
+/** Select driver: HARD, SOFT, or NONE. */
+#define AC_SPI0_DRIVER SOFT
+/** For software SPI, specify SCK IO port. */
+#define AC_SPI0_SOFT_SCK_IO D, 5
+/** For software SPI, specify MOSI IO port. */
+#define AC_SPI0_SOFT_MOSI_IO D, 7
+/** For software SPI, specify MISO IO port. */
+#define AC_SPI0_SOFT_MISO_IO D, 6
+/** Same thing for an optionnal second SPI driver. */
+#define AC_SPI1_DRIVER NONE
+
/* isp - ISP module. */
/** Size of isp_frame buffer. */
#define AC_ISP_FRAME_BUFFER_SIZE 275
/** Should be implemented by the user to send a character. */
-#define AC_ISP_FRAME_SEND_CHAR isp_send_char
+#define AC_ISP_FRAME_SEND_CHAR usb_isp_send_char
/** Should be implemented by the user (isp_proto) to accept a frame. */
#define AC_ISP_FRAME_ACCEPT_FRAME isp_proto_accept
-/** Should be implemeted by the user to send a frame. */
+/** Should be implemented by the user to send a frame. */
#define AC_ISP_PROTO_SEND isp_frame_send_frame
+/** Programmer signature. */
+#define AC_ISP_PROTO_SIGNATURE "APBisp_2"
+/** Programmer build number. */
+#define AC_ISP_PROTO_BUILD_NUMBER 0x0100
+/** Programmer hardware version. */
+#define AC_ISP_PROTO_HW_VERSION 0x02
+/** Programmer software version. */
+#define AC_ISP_PROTO_SW_VERSION 0x0204
+/** Should be implemented by the user to enable SPI programming:
+ * - set RESET and SCK to low,
+ * - power on, or if not possible, do a positive RESET pulse,
+ * - enable SPI. */
+#define AC_ISP_SPI_ENABLE usb_isp_spi_enable
+/** Should be implemented by the user to disable SPI programming:
+ * - disable SPI,
+ * - release RESET,
+ * - power off if desired. */
+#define AC_ISP_SPI_DISABLE usb_isp_spi_disable
+/** Should be implemented by the user to do a pulse on SCK. This is used to
+ * try to resynchronise. */
+#define AC_ISP_SPI_SCK_PULSE usb_isp_spi_sck_pulse
+/** Should be implemented by the user to send and receive a byte using the SPI
+ * bus. */
+#define AC_ISP_SPI_TX usb_isp_spi_tx
/* usb */
#include "modules/usb/lufaconfig.h"
diff --git a/digital/dev2/src/usb_serial_isp/main.c b/digital/dev2/src/usb_serial_isp/main.c
index 849b9942..9639fd83 100644
--- a/digital/dev2/src/usb_serial_isp/main.c
+++ b/digital/dev2/src/usb_serial_isp/main.c
@@ -32,6 +32,7 @@
#include "descriptors.h"
#include "common/serial.h"
+#include "common/usb_isp.h"
#include "common/select.h"
HANDLES_EVENT (USB_Connect);
@@ -41,47 +42,6 @@ HANDLES_EVENT (USB_UnhandledControlPacket);
volatile uint8_t usb_connected, usb_configured;
-uint8_t isp_sent;
-
-void
-isp_send_char (uint8_t c)
-{
- Endpoint_SelectEndpoint (ISP_TX_EPNUM);
- /* Wait endpoint to become ready. */
- while (!Endpoint_ReadWriteAllowed ())
- ;
- Endpoint_Write_Byte (c);
- /* If at end of endpoint buffer, send. */
- if (!Endpoint_ReadWriteAllowed ())
- Endpoint_ClearCurrentBank ();
- /* Select back RX endpoint. */
- Endpoint_SelectEndpoint (ISP_RX_EPNUM);
- /* Will need extra clear at end of all transfers. */
- isp_sent = 1;
-}
-
-static void
-isp_task (void)
-{
- Endpoint_SelectEndpoint (ISP_RX_EPNUM);
- /* If data is available from USB: */
- if (Endpoint_ReadWriteAllowed ())
- {
- /* Read as much as possible, and clear endpoint. */
- do {
- isp_frame_accept_char (Endpoint_Read_Byte ());
- } while (Endpoint_ReadWriteAllowed ());
- Endpoint_ClearCurrentBank ();
- }
- /* If data has been sent, sent a ZLP or finalise last packet. */
- if (isp_sent)
- {
- Endpoint_SelectEndpoint (ISP_TX_EPNUM);
- Endpoint_ClearCurrentBank ();
- isp_sent = 0;
- }
-}
-
int
main (void)
{
@@ -102,7 +62,7 @@ main (void)
if (usb_configured)
{
serial_task ();
- isp_task ();
+ usb_isp_task ();
}
}
}