aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lufa/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.h
blob: 44b339762d1cc07ceb01302c7917ade9cd06b42e (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
/*
             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 ISPProtocol.c.
 */

#ifndef _ISP_PROTOCOL_
#define _ISP_PROTOCOL_

	/* Includes: */
		#include <avr/io.h>
		#include <util/delay.h>

		#include <LUFA/Drivers/USB/USB.h>

		#include "../V2Protocol.h"
		#include "Config/AppConfig.h"

	/* Preprocessor Checks: */
		#if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
			#undef ENABLE_ISP_PROTOCOL

			#if !defined(ENABLE_XPROG_PROTOCOL)
				#define ENABLE_XPROG_PROTOCOL
			#endif
		#endif

	/* Macros: */
		/** Mask for the reading or writing of the high byte in a FLASH word when issuing a low-level programming command. */
		#define READ_WRITE_HIGH_BYTE_MASK       (1 << 3)

		#define PROG_MODE_PAGED_WRITES_MASK     (1 << 0)
		#define PROG_MODE_WORD_TIMEDELAY_MASK   (1 << 1)
		#define PROG_MODE_WORD_VALUE_MASK       (1 << 2)
		#define PROG_MODE_WORD_READYBUSY_MASK   (1 << 3)
		#define PROG_MODE_PAGED_TIMEDELAY_MASK  (1 << 4)
		#define PROG_MODE_PAGED_VALUE_MASK      (1 << 5)
		#define PROG_MODE_PAGED_READYBUSY_MASK  (1 << 6)
		#define PROG_MODE_COMMIT_PAGE_MASK      (1 << 7)

	/* Function Prototypes: */
		void ISPProtocol_EnterISPMode(void);
		void ISPProtocol_LeaveISPMode(void);
		void ISPProtocol_ProgramMemory(const uint8_t V2Command);
		void ISPProtocol_ReadMemory(const uint8_t V2Command);
		void ISPProtocol_ChipErase(void);
		void ISPProtocol_ReadFuseLockSigOSCCAL(const uint8_t V2Command);
		void ISPProtocol_WriteFuseLock(const uint8_t V2Command);
		void ISPProtocol_SPIMulti(void);
		void ISPProtocol_DelayMS(uint8_t DelayMS);
#endif
>vs->depth); pixel_t *irow = (pixel_t *)row; int j, i; pixel_t *last_bg = (pixel_t *)last_bg32; pixel_t *last_fg = (pixel_t *)last_fg32; pixel_t bg = 0; pixel_t fg = 0; int n_colors = 0; int bg_count = 0; int fg_count = 0; int flags = 0; uint8_t data[(sizeof(pixel_t) + 2) * 16 * 16]; int n_data = 0; int n_subtiles = 0; for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { switch (n_colors) { case 0: bg = irow[i]; n_colors = 1; break; case 1: if (irow[i] != bg) { fg = irow[i]; n_colors = 2; } break; case 2: if (irow[i] != bg && irow[i] != fg) { n_colors = 3; } else { if (irow[i] == bg) bg_count++; else if (irow[i] == fg) fg_count++; } break; default: break; } } if (n_colors > 2) break; irow += vs->ds->linesize / sizeof(pixel_t); } if (n_colors > 1 && fg_count > bg_count) { pixel_t tmp = fg; fg = bg; bg = tmp; } if (!*has_bg || *last_bg != bg) { flags |= 0x02; *has_bg = 1; *last_bg = bg; } if (!*has_fg || *last_fg != fg) { flags |= 0x04; *has_fg = 1; *last_fg = fg; } switch (n_colors) { case 1: n_data = 0; break; case 2: flags |= 0x08; irow = (pixel_t *)row; for (j = 0; j < h; j++) { int min_x = -1; for (i = 0; i < w; i++) { if (irow[i] == fg) { if (min_x == -1) min_x = i; } else if (min_x != -1) { hextile_enc_cord(data + n_data, min_x, j, i - min_x, 1); n_data += 2; n_subtiles++; min_x = -1; } } if (min_x != -1) { hextile_enc_cord(data + n_data, min_x, j, i - min_x, 1); n_data += 2; n_subtiles++; } irow += vs->ds->linesize / sizeof(pixel_t); } break; case 3: flags |= 0x18; irow = (pixel_t *)row; if (!*has_bg || *last_bg != bg) flags |= 0x02; for (j = 0; j < h; j++) { int has_color = 0; int min_x = -1; pixel_t color; for (i = 0; i < w; i++) { if (!has_color) { if (irow[i] == bg) continue; color = irow[i]; min_x = i; has_color = 1; } else if (irow[i] != color) { has_color = 0; #ifdef GENERIC vnc_convert_pixel(vs, data + n_data, color); n_data += vs->pix_bpp; #else memcpy(data + n_data, &color, sizeof(color)); n_data += sizeof(pixel_t); #endif hextile_enc_cord(data + n_data, min_x, j, i - min_x, 1); n_data += 2; n_subtiles++; min_x = -1; if (irow[i] != bg) { color = irow[i]; min_x = i; has_color = 1; } } } if (has_color) { #ifdef GENERIC vnc_convert_pixel(vs, data + n_data, color); n_data += vs->pix_bpp; #else memcpy(data + n_data, &color, sizeof(color)); n_data += sizeof(pixel_t); #endif hextile_enc_cord(data + n_data, min_x, j, i - min_x, 1); n_data += 2; n_subtiles++; } irow += vs->ds->linesize / sizeof(pixel_t); } /* A SubrectsColoured subtile invalidates the foreground color */ *has_fg = 0; if (n_data > (w * h * sizeof(pixel_t))) { n_colors = 4; flags = 0x01; *has_bg = 0; /* we really don't have to invalidate either the bg or fg but we've lost the old values. oh well. */ } default: break; } if (n_colors > 3) { flags = 0x01; *has_fg = 0; *has_bg = 0; n_colors = 4; } vnc_write_u8(vs, flags); if (n_colors < 4) { if (flags & 0x02) vs->write_pixels(vs, last_bg, sizeof(pixel_t)); if (flags & 0x04) vs->write_pixels(vs, last_fg, sizeof(pixel_t)); if (n_subtiles) { vnc_write_u8(vs, n_subtiles); vnc_write(vs, data, n_data); } } else { for (j = 0; j < h; j++) { vs->write_pixels(vs, row, w * vs->depth); row += vs->ds->linesize; } } } #undef NAME #undef pixel_t #undef CONCAT_I #undef CONCAT