aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lufa/Demos/Host/LowLevel/StillImageHost/StillImageHost.h
blob: 43ad59c96792e47050fc5e956285061b0620484b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
             LUFA Library
     Copyright (C) Dean Camera, 2017.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

/*
  Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)

  Permission to use, copy, modify, distribute, and sell this
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in
  all copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.

  The author disclaims all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

/** \file
 *
 *  Header file for StillImageHost.c.
 */

#ifndef _STILL_IMAGE_HOST_H_
#define _STILL_IMAGE_HOST_H_

	/* Includes: */
		#include <avr/io.h>
		#include <avr/wdt.h>
		#include <avr/power.h>
		#include <avr/interrupt.h>
		#include <stdio.h>

		#include "ConfigDescriptor.h"

		#include "Lib/StillImageCommands.h"

		#include <LUFA/Drivers/Misc/TerminalCodes.h>
		#include <LUFA/Drivers/USB/USB.h>
		#include <LUFA/Drivers/Peripheral/Serial.h>
		#include <LUFA/Drivers/Board/LEDs.h>
		#include <LUFA/Platform/Platform.h>

	/* Macros: */
		/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
		#define LEDMASK_USB_NOTREADY      LEDS_LED1

		/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
		#define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)

		/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
		#define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)

		/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
		#define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)

		/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
		#define LEDMASK_USB_BUSY          LEDS_LED2

	/* Function Prototypes: */
		void SetupHardware(void);
		void StillImageHost_Task(void);

		void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
		void EVENT_USB_Host_DeviceAttached(void);
		void EVENT_USB_Host_DeviceUnattached(void);
		void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
		                                            const uint8_t SubErrorCode);
		void EVENT_USB_Host_DeviceEnumerationComplete(void);

		void UnicodeToASCII(uint8_t* UnicodeString,
		                    char* Buffer);
		void ShowCommandError(uint8_t ErrorCode,
		                      bool ResponseCodeError);

#endif
B cyclonev_mlab_cell `define RAM_BLOCK cyclonev_ram_block `define IBUF cyclonev_io_ibuf `define OBUF cyclonev_io_obuf `define CLKENA cyclonev_clkena `endif `ifdef arriav `define LCELL arriav_lcell_comb `define MAC arriav_mac `define MLAB arriav_mlab_cell `define RAM_BLOCK arriav_ram_block `define IBUF arriav_io_ibuf `define OBUF arriav_io_obuf `define CLKENA arriav_clkena `endif `ifdef cyclone10gx `define LCELL cyclone10gx_lcell_comb `define MAC cyclone10gx_mac `define MLAB cyclone10gx_mlab_cell `define RAM_BLOCK cyclone10gx_ram_block `define IBUF cyclone10gx_io_ibuf `define OBUF cyclone10gx_io_obuf `define CLKENA cyclone10gx_clkena `endif module __MISTRAL_VCC(output Q); MISTRAL_ALUT2 #(.LUT(4'b1111)) _TECHMAP_REPLACE_ (.A(1'b1), .B(1'b1), .Q(Q)); endmodule module __MISTRAL_GND(output Q); MISTRAL_ALUT2 #(.LUT(4'b0000)) _TECHMAP_REPLACE_ (.A(1'b1), .B(1'b1), .Q(Q)); endmodule module MISTRAL_FF(input DATAIN, CLK, ACLR, ENA, SCLR, SLOAD, SDATA, output reg Q); dffeas #(.power_up("low"), .is_wysiwyg("true")) _TECHMAP_REPLACE_ (.d(DATAIN), .clk(CLK), .clrn(ACLR), .ena(ENA), .sclr(SCLR), .sload(SLOAD), .asdata(SDATA), .q(Q)); endmodule module MISTRAL_ALUT6(input A, B, C, D, E, F, output Q); parameter [63:0] LUT = 64'h0000_0000_0000_0000; `LCELL #(.lut_mask(LUT)) _TECHMAP_REPLACE_ (.dataa(A), .datab(B), .datac(C), .datad(D), .datae(E), .dataf(F), .combout(Q)); endmodule module MISTRAL_ALUT5(input A, B, C, D, E, output Q); parameter [31:0] LUT = 32'h0000_0000; `LCELL #(.lut_mask({2{LUT}})) _TECHMAP_REPLACE_ (.dataa(A), .datab(B), .datac(C), .datad(D), .datae(E), .combout(Q)); endmodule module MISTRAL_ALUT4(input A, B, C, D, output Q); parameter [15:0] LUT = 16'h0000; `LCELL #(.lut_mask({4{LUT}})) _TECHMAP_REPLACE_ (.dataa(A), .datab(B), .datac(C), .datad(D), .combout(Q)); endmodule module MISTRAL_ALUT3(input A, B, C, output Q); parameter [7:0] LUT = 8'h00; `LCELL #(.lut_mask({8{LUT}})) _TECHMAP_REPLACE_ (.dataa(A), .datab(B), .datac(C), .combout(Q)); endmodule module MISTRAL_ALUT2(input A, B, output Q); parameter [3:0] LUT = 4'h0; `LCELL #(.lut_mask({16{LUT}})) _TECHMAP_REPLACE_ (.dataa(A), .datab(B), .combout(Q)); endmodule module MISTRAL_NOT(input A, output Q); NOT _TECHMAP_REPLACE_ (.IN(A), .OUT(Q)); endmodule module MISTRAL_ALUT_ARITH(input A, B, C, D0, D1, CI, output SO, CO); parameter LUT0 = 16'h0000; parameter LUT1 = 16'h0000; `LCELL #(.lut_mask({16'h0, LUT1, 16'h0, LUT0})) _TECHMAP_REPLACE_ (.dataa(A), .datab(B), .datac(C), .datad(D0), .dataf(D1), .cin(CI), .sumout(SO), .cout(CO)); endmodule module MISTRAL_MLAB(input [4:0] A1ADDR, input A1DATA, A1EN, CLK1, input [4:0] B1ADDR, output B1DATA); parameter _TECHMAP_CELLNAME_ = ""; // Here we get to an unfortunate situation. The cell has a mem_init0 parameter, // which takes in a hexadecimal string that could be used to initialise RAM. // In the vendor simulation models, this appears to work fine, but Quartus, // either intentionally or not, forgets about this parameter and initialises the // RAM to zero. // // Because of this, RAM initialisation is presently disabled, but the source // used to generate mem_init0 is kept (commented out) in case this gets fixed // or an undocumented way to get Quartus to initialise from mem_init0 is found. `MLAB #( .logical_ram_name(_TECHMAP_CELLNAME_), .logical_ram_depth(32), .logical_ram_width(1), .mixed_port_feed_through_mode("Dont Care"), .first_bit_number(0), .first_address(0), .last_address(31), .address_width(5), .data_width(1), .byte_enable_mask_width(1), .port_b_data_out_clock("NONE"), // .mem_init0($sformatf("%08x", INIT)) ) _TECHMAP_REPLACE_ ( .portaaddr(A1ADDR), .portadatain(A1DATA), .portbaddr(B1ADDR), .portbdataout(B1DATA), .ena0(A1EN), .clk0(CLK1) ); endmodule module MISTRAL_M10K(A1ADDR, A1DATA, A1EN, CLK1, B1ADDR, B1DATA, B1EN); parameter CFG_ABITS = 10; parameter CFG_DBITS = 10; parameter _TECHMAP_CELLNAME_ = ""; input [CFG_ABITS-1:0] A1ADDR, B1ADDR; input [CFG_DBITS-1:0] A1DATA; input CLK1, A1EN, B1EN; output [CFG_DBITS-1:0] B1DATA; // Much like the MLAB, the M10K has mem_init[01234] parameters which would let // you initialise the RAM cell via hex literals. If they were implemented. `RAM_BLOCK #( .operation_mode("dual_port"), .logical_ram_name(_TECHMAP_CELLNAME_), .port_a_address_width(CFG_ABITS), .port_a_data_width(CFG_DBITS), .port_a_logical_ram_depth(2**CFG_ABITS), .port_a_logical_ram_width(CFG_DBITS), .port_a_first_address(0), .port_a_last_address(2**CFG_ABITS - 1), .port_a_first_bit_number(0), .port_b_address_width(CFG_ABITS), .port_b_data_width(CFG_DBITS), .port_b_logical_ram_depth(2**CFG_ABITS), .port_b_logical_ram_width(CFG_DBITS), .port_b_first_address(0), .port_b_last_address(2**CFG_ABITS - 1), .port_b_first_bit_number(0), .port_b_address_clock("clock0"), .port_b_read_enable_clock("clock0") ) _TECHMAP_REPLACE_ ( .portaaddr(A1ADDR), .portadatain(A1DATA), .portawe(A1EN), .portbaddr(B1ADDR), .portbdataout(B1DATA), .portbre(B1EN), .clk0(CLK1) ); endmodule module MISTRAL_MUL27X27(input [26:0] A, B, output [53:0] Y); parameter A_SIGNED = 1; parameter B_SIGNED = 1; `MAC #( .ax_width(27), .signed_max(A_SIGNED ? "true" : "false"), .ay_scan_in_width(27), .signed_may(B_SIGNED ? "true" : "false"), .result_a_width(54), .operation_mode("M27x27") ) _TECHMAP_REPLACE_ ( .ax(A), .ay(B), .resulta(Y) ); endmodule module MISTRAL_MUL18X18(input [17:0] A, B, output [35:0] Y); parameter A_SIGNED = 1; parameter B_SIGNED = 1; `MAC #( .ax_width(18), .signed_max(A_SIGNED ? "true" : "false"), .ay_scan_in_width(18), .signed_may(B_SIGNED ? "true" : "false"), .result_a_width(36), .operation_mode("M18x18_FULL") ) _TECHMAP_REPLACE_ ( .ax(A), .ay(B), .resulta(Y) ); endmodule module MISTRAL_MUL9X9(input [8:0] A, B, output [17:0] Y); parameter A_SIGNED = 1; parameter B_SIGNED = 1; `MAC #( .ax_width(9), .signed_max(A_SIGNED ? "true" : "false"), .ay_scan_in_width(9), .signed_may(B_SIGNED ? "true" : "false"), .result_a_width(18), .operation_mode("M9x9") ) _TECHMAP_REPLACE_ ( .ax(A), .ay(B), .resulta(Y) ); endmodule module MISTRAL_IB(input PAD, output O); `IBUF #( .bus_hold("false"), .differential_mode("false") ) _TECHMAP_REPLACE_ ( .i(PAD), .o(O) ); endmodule module MISTRAL_OB(output PAD, input I, OE); `OBUF #( .bus_hold("false"), .differential_mode("false") ) _TECHMAP_REPLACE_ ( .i(I), .o(PAD), .oe(OE) ); endmodule module MISTRAL_IO(output PAD, input I, OE, output O); `IBUF #( .bus_hold("false"), .differential_mode("false") ) ibuf ( .i(PAD), .o(O) ); `OBUF #( .bus_hold("false"), .differential_mode("false") ) obuf ( .i(I), .o(PAD), .oe(OE) ); endmodule module MISTRAL_CLKBUF (input A, output Q); `CLKENA #( .clock_type("auto"), .ena_register_mode("always enabled"), .ena_register_power_up("high"), .disable_mode("low"), .test_syn("high") ) _TECHMAP_REPLACE_ ( .inclk(A), .ena(1'b1), .outclk(Q) ); endmodule