Skip to content

Commit

Permalink
refactor: remove comment and unused lines
Browse files Browse the repository at this point in the history
  • Loading branch information
edy555 committed Feb 24, 2018
1 parent 6711d48 commit 1377906
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 303 deletions.
126 changes: 2 additions & 124 deletions ili9341.c
Expand Up @@ -123,19 +123,6 @@ send_command(uint8_t cmd, int len, const uint8_t *data)
//CS_HIGH;
}

void
send_command16(uint8_t cmd, int data)
{
CS_LOW;
DC_CMD;
ssp_databit8();
ssp_senddata(cmd);
DC_DATA;
ssp_databit16();
ssp_senddata16(data);
CS_HIGH;
}

const uint8_t ili9341_init_seq[] = {
// cmd, len, data...,
// Power control B
Expand Down Expand Up @@ -247,20 +234,6 @@ void ili9341_fill(int x, int y, int w, int h, int color)
ssp_senddata16(color);
}

#if 0
void ili9341_bulk(int x, int y, int w, int h)
{
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
uint16_t *buf = spi_buffer;
int len = w * h;
send_command(0x2A, 4, xx);
send_command(0x2B, 4, yy);
send_command(0x2C, 0, NULL);
while (len-- > 0)
ssp_senddata16(*buf++);
}
#else
void ili9341_draw_bitmap(int x, int y, int w, int h, uint16_t *buf)
{
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
Expand All @@ -278,12 +251,6 @@ void ili9341_draw_bitmap(int x, int y, int w, int h, uint16_t *buf)
dmaWaitCompletion(dmatx);
}

void ili9341_bulk(int x, int y, int w, int h)
{
ili9341_draw_bitmap(x, y, w, h, spi_buffer);
}
#endif

void
ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg)
{
Expand All @@ -297,7 +264,7 @@ ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg)
bits <<= 1;
}
}
ili9341_bulk(x, y, 5, 7);
ili9341_draw_bitmap(x, y, 5, 7, spi_buffer);
}

void
Expand All @@ -312,42 +279,6 @@ ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg)

#define SWAP(x,y) do { int z=x; x = y; y = z; } while(0)

void
ili9341_line(int x0, int y0, int x1, int y1, uint16_t fg)
{
if (x0 > x1) {
SWAP(x0, x1);
SWAP(y0, y1);
}

while (x0 <= x1) {
int dx = x1 - x0 + 1;
int dy = y1 - y0;
if (dy >= 0) {
dy++;
if (dy > dx) {
dy /= dx; dx = 1;
} else {
dx /= dy; dy = 1;
}
} else {
dy--;
if (-dy > dx) {
dy /= dx; dx = 1;
} else {
dx /= -dy; dy = -1;
}
}
if (dy > 0)
ili9341_fill(x0, y0, dx, dy, fg);
else
ili9341_fill(x0, y0+dy, dx, -dy, fg);
x0 += dx;
y0 += dy;
}
}


const font_t NF20x24 = { 20, 24, 1, 24, 1, (const uint32_t *)numfont20x24 };
const font_t NF32x24 = { 32, 24, 1, 24, 1, (const uint32_t *)numfont32x24 };
const font_t NF32x48 = { 32, 48, 2, 24, 1, (const uint32_t *)numfont32x24 };
Expand All @@ -373,7 +304,7 @@ ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint
}
}
}
ili9341_bulk(x, y, font->width, font->height);
ili9341_draw_bitmap(x, y, font->width, font->height, spi_buffer);
}

void
Expand All @@ -394,56 +325,3 @@ ili9341_drawfont_string(const char *str, const font_t *font, int x, int y, uint1
x += font->width;
}
}

#if 0
static const uint16_t colormap[] = {
RGB565(255,0,0), RGB565(0,255,0), RGB565(0,0,255),
RGB565(255,255,0), RGB565(0,255,255), RGB565(255,0,255)
};

void
ili9341_test(int mode)
{
int x, y;
int i;
switch (mode) {
default:
#if 1
ili9341_fill(0, 0, 320, 240, 0);
for (y = 0; y < 240; y++) {
ili9341_fill(0, y, 320, 1, RGB565(y, (y + 120) % 256, 240-y));
}
break;
case 1:
ili9341_fill(0, 0, 320, 240, 0);
for (y = 0; y < 240; y++) {
for (x = 0; x < 320; x++) {
ili9341_pixel(x, y, (y<<8)|x);
}
}
break;
case 2:
//send_command16(0x55, 0xff00);
ili9341_pixel(64, 64, 0xaa55);
break;
#endif
#if 1
case 3:
for (i = 0; i < 10; i++)
ili9341_drawfont(i, &NF20x24, i*20, 120, colormap[i%6], 0x0000);
break;
#endif
#if 0
case 4:
draw_grid(10, 8, 29, 29, 15, 0, 0xffff, 0);
break;
#endif
case 4:
ili9341_line(0, 0, 15, 100, 0xffff);
ili9341_line(0, 0, 100, 100, 0xffff);
ili9341_line(0, 15, 100, 0, 0xffff);
ili9341_line(0, 100, 100, 0, 0xffff);
break;
}
}
#endif
179 changes: 0 additions & 179 deletions si5351_low.c
Expand Up @@ -105,182 +105,3 @@ si5351_setup(void)
i2c_init(I2C1);
si5351_init_bulk();
}

#if 0
static void
si5351_write(uint8_t reg, uint8_t dat)
{
uint8_t buf[2];
buf[0] = reg;
buf[1] = dat;
i2cSendByte(I2C1, SI5351_I2C_ADDR, buf, 2);
}

void
si5351_init(void)
{
//i2cInit(I2C1);

// Disable all output
si5351_write(SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0xff);

// Initialize the CLK outputs according to flowchart in datasheet
// First, turn them off
si5351_write(SI5351_REG_16_CLK0_CONTROL, SI5351_CLK_POWERDOWN);
si5351_write(SI5351_REG_17_CLK1_CONTROL, SI5351_CLK_POWERDOWN);
si5351_write(SI5351_REG_18_CLK2_CONTROL, SI5351_CLK_POWERDOWN);

si5351_write(SI5351_REG_183_CRYSTAL_LOAD, SI5351_CRYSTAL_LOAD_8PF);

// Then reset the PLLs
si5351_write(SI5351_REG_177_PLL_RESET, SI5351_PLL_RESET_A | SI5351_PLL_RESET_B);
}

void si5351_setupPLL(uint8_t pll, /* SI5351_PLL_A or SI5351_PLL_B */
uint8_t mult,
uint32_t num,
uint32_t denom)
{
/* Get the appropriate starting point for the PLL registers */
const uint8_t pllreg_base[] = {
SI5351_REG_26_PLL_A,
SI5351_REG_34_PLL_B
};
uint8_t baseaddr = pllreg_base[pll];

uint32_t P1;
uint32_t P2;
uint32_t P3;

/* Feedback Multisynth Divider Equation
* where: a = mult, b = num and c = denom
* P1 register is an 18-bit value using following formula:
* P1[17:0] = 128 * mult + floor(128*(num/denom)) - 512
* P2 register is a 20-bit value using the following formula:
* P2[19:0] = 128 * num - denom * floor(128*(num/denom))
* P3 register is a 20-bit value using the following formula:
* P3[19:0] = denom
*/

/* Set the main PLL config registers */
if (num == 0)
{
/* Integer mode */
P1 = 128 * mult - 512;
P2 = num;
P3 = denom;
}
else
{
/* Fractional mode */
//P1 = (uint32_t)(128 * mult + floor(128 * ((float)num/(float)denom)) - 512);
P1 = 128 * mult + ((128 * num) / denom) - 512;
//P2 = (uint32_t)(128 * num - denom * floor(128 * ((float)num/(float)denom)));
P2 = 128 * num - denom * ((128 * num) / denom);
P3 = denom;
}

/* The datasheet is a nightmare of typos and inconsistencies here! */
si5351_write(baseaddr, (P3 & 0x0000FF00) >> 8);
si5351_write(baseaddr+1, (P3 & 0x000000FF));
si5351_write(baseaddr+2, (P1 & 0x00030000) >> 16);
si5351_write(baseaddr+3, (P1 & 0x0000FF00) >> 8);
si5351_write(baseaddr+4, (P1 & 0x000000FF));
si5351_write(baseaddr+5, ((P3 & 0x000F0000) >> 12) | ((P2 & 0x000F0000) >> 16) );
si5351_write(baseaddr+6, (P2 & 0x0000FF00) >> 8);
si5351_write(baseaddr+7, (P2 & 0x000000FF));

/* Reset both PLLs */
si5351_write(SI5351_REG_177_PLL_RESET, SI5351_PLL_RESET_A | SI5351_PLL_RESET_B);
}

void
si5351_setupMultisynth(uint8_t output,
uint8_t pllSource,
uint32_t div,
uint32_t num,
uint32_t denom)
{
/* Get the appropriate starting point for the PLL registers */
uint8_t msreg_base[] = {
SI5351_REG_42_MULTISYNTH0,
SI5351_REG_50_MULTISYNTH1,
SI5351_REG_58_MULTISYNTH2,
};
uint8_t baseaddr = msreg_base[output];
const uint8_t clkctrl[] = {
SI5351_REG_16_CLK0_CONTROL,
SI5351_REG_17_CLK1_CONTROL,
SI5351_REG_18_CLK2_CONTROL
};
uint8_t dat;

uint32_t P1;
uint32_t P2;
uint32_t P3;

/* Output Multisynth Divider Equations
* where: a = div, b = num and c = denom
* P1 register is an 18-bit value using following formula:
* P1[17:0] = 128 * a + floor(128*(b/c)) - 512
* P2 register is a 20-bit value using the following formula:
* P2[19:0] = 128 * b - c * floor(128*(b/c))
* P3 register is a 20-bit value using the following formula:
* P3[19:0] = c
*/
/* Set the main PLL config registers */
if (num == 0)
{
/* Integer mode */
P1 = 128 * div - 512;
P2 = num;
P3 = denom;
}
else
{
/* Fractional mode */
//P1 = (uint32_t)(128 * div + floor(128 * ((float)num/(float)denom)) - 512);
P1 = 128 * div + ((128 * num) / denom) - 512;
//P2 = (uint32_t)(128 * num - denom * floor(128 * ((float)num/(float)denom)));
P2 = 128 * num - denom * ((128 * num) / denom);
P3 = denom;
}

/* Set the MSx config registers */
si5351_write(baseaddr, (P3 & 0x0000FF00) >> 8);
si5351_write(baseaddr+1, (P3 & 0x000000FF));
si5351_write(baseaddr+2, (P1 & 0x00030000) >> 16); /* ToDo: Add DIVBY4 (>150MHz) and R0 support (<500kHz) later */
si5351_write(baseaddr+3, (P1 & 0x0000FF00) >> 8);
si5351_write(baseaddr+4, (P1 & 0x000000FF));
si5351_write(baseaddr+5, ((P3 & 0x000F0000) >> 12) | ((P2 & 0x000F0000) >> 16));
si5351_write(baseaddr+6, (P2 & 0x0000FF00) >> 8);
si5351_write(baseaddr+7, (P2 & 0x000000FF));

/* Configure the clk control and enable the output */
dat = SI5351_CLK_DRIVE_STRENGTH_2MA | SI5351_CLK_INPUT_MULTISYNTH_N;
if (pllSource == SI5351_PLL_B)
dat |= SI5351_CLK_PLL_SELECT_B;
if (num == 0)
dat |= SI5351_CLK_INTEGER_MODE;
si5351_write(clkctrl[output], dat);
}

void
si5351_setup(void)
{
i2c_init_low(I2C1);

si5351_init();

// Set PLLA 800MHz
si5351_setupPLL(SI5351_PLL_A, 32, 0, 1);
//si5351_setupPLL(SI5351_PLL_B, 32, 0, 1);

// Set CLK2 as PLLA/100 = 8MHz
//si5351_setupMultisynth(0, SI5351_PLL_A, 32, 0, 1);
//si5351_setupMultisynth(1, SI5351_PLL_B, 45, 1, 2);
si5351_setupMultisynth(2, SI5351_PLL_A, 100, 0, 1);

si5351_write(SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0x00);
}
#endif

0 comments on commit 1377906

Please sign in to comment.