as3525: make sure we don't use a negative number of sectors
[kugel-rb.git] / firmware / target / arm / as3525 / sansa-clipplus / lcd-clip-plus.c
blob1a9454750543a277ef811f0aa4c9ef56d50ad379
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 François Dinel
11 * Copyright (C) 2008-2009 Rafaël Carré
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
22 #include "config.h"
24 #include "lcd.h"
25 #include "lcd-clip.h"
26 #include "system.h"
27 #include "cpu.h"
29 void lcd_hw_init(void)
31 CGU_PERI |= CGU_SSP_CLOCK_ENABLE;
33 SSP_CPSR = AS3525_SSP_PRESCALER; /* OF = 0x10 */
34 SSP_CR0 = (1<<7) | (1<<6) | 7; /* Motorola SPI frame format, 8 bits */
35 SSP_CR1 = (1<<3) | (1<<1); /* SSP Operation enabled */
36 SSP_IMSC = 0; /* No interrupts */
38 GPIOA_DIR |= (1<<5);
39 GPIOB_DIR |= (1<<2) | (1<<7);
40 GPIOB_PIN(7) = 0;
41 GPIOA_PIN(5) = (1<<5);
44 void lcd_write_command(int byte)
46 while(SSP_SR & (1<<4)) /* BSY flag */
49 GPIOB_PIN(2) = 0;
50 SSP_DATA = byte;
52 while(SSP_SR & (1<<4)) /* BSY flag */
56 void lcd_write_data(const fb_data* p_bytes, int count)
58 GPIOB_PIN(2) = (1<<2);
60 while (count--)
62 while(!(SSP_SR & (1<<1))) /* wait until transmit FIFO is not full */
65 SSP_DATA = *p_bytes++;