LED PWM
This commit is contained in:
parent
97316353c3
commit
b7654290a1
@ -224,9 +224,9 @@ uint32_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
|
||||
_delay_ms(30); */
|
||||
}
|
||||
} else {
|
||||
TCHAR* sfn = fno.fname;
|
||||
while(*sfn != 0) {
|
||||
crc += crc32_update(crc, *((unsigned char*)sfn++));
|
||||
TCHAR* fn2 = fn;
|
||||
while(*fn2 != 0) {
|
||||
crc += crc32_update(crc, *((unsigned char*)fn2++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
80
src/led.c
80
src/led.c
@ -5,25 +5,53 @@
|
||||
#include "timer.h"
|
||||
#include "led.h"
|
||||
|
||||
static uint8_t led_bright[16]={255,253,252,251,249,247,244,239,232,223,210,191,165,127,74,0};
|
||||
|
||||
int led_rdyledstate = 0;
|
||||
int led_readledstate = 0;
|
||||
int led_writeledstate = 0;
|
||||
int led_pwmstate = 0;
|
||||
|
||||
void rdyled(unsigned int state) {
|
||||
BITBAND(LPC_GPIO2->FIODIR, 0) = state;
|
||||
if(led_pwmstate) {
|
||||
rdybright(state?15:0);
|
||||
} else {
|
||||
BITBAND(LPC_GPIO2->FIODIR, 0) = state;
|
||||
}
|
||||
led_rdyledstate = state;
|
||||
}
|
||||
|
||||
void readled(unsigned int state) {
|
||||
BITBAND(LPC_GPIO2->FIODIR, 1) = state;
|
||||
if(led_pwmstate) {
|
||||
readbright(state?15:0);
|
||||
} else {
|
||||
BITBAND(LPC_GPIO2->FIODIR, 1) = state;
|
||||
}
|
||||
led_readledstate = state;
|
||||
}
|
||||
|
||||
void writeled(unsigned int state) {
|
||||
BITBAND(LPC_GPIO2->FIODIR, 2) = state;
|
||||
if(led_pwmstate) {
|
||||
writebright(state?15:0);
|
||||
} else {
|
||||
BITBAND(LPC_GPIO2->FIODIR, 2) = state;
|
||||
}
|
||||
led_writeledstate = state;
|
||||
}
|
||||
|
||||
void rdybright(uint8_t bright) {
|
||||
LPC_PWM1->MR1 = led_bright[(bright & 15)];
|
||||
BITBAND(LPC_PWM1->LER, 1) = 1;
|
||||
}
|
||||
void readbright(uint8_t bright) {
|
||||
LPC_PWM1->MR2 = led_bright[(bright & 15)];
|
||||
BITBAND(LPC_PWM1->LER, 2) = 1;
|
||||
}
|
||||
void writebright(uint8_t bright) {
|
||||
LPC_PWM1->MR3 = led_bright[(bright & 15)];
|
||||
BITBAND(LPC_PWM1->LER, 3) = 1;
|
||||
}
|
||||
|
||||
void led_clkout32(uint32_t val) {
|
||||
while(1) {
|
||||
rdyled(1);
|
||||
@ -55,3 +83,49 @@ void led_panic() {
|
||||
delay_ms(350);
|
||||
}
|
||||
}
|
||||
|
||||
void led_pwm() {
|
||||
/* connect PWM to P2.0 - P2.2 */
|
||||
/* XXX Rev.B P2.???? */
|
||||
BITBAND(LPC_PINCON->PINSEL4, 1) = 0;
|
||||
BITBAND(LPC_PINCON->PINSEL4, 3) = 0;
|
||||
BITBAND(LPC_PINCON->PINSEL4, 5) = 0;
|
||||
|
||||
BITBAND(LPC_PINCON->PINSEL4, 0) = 1;
|
||||
BITBAND(LPC_PINCON->PINSEL4, 2) = 1;
|
||||
BITBAND(LPC_PINCON->PINSEL4, 4) = 1;
|
||||
|
||||
BITBAND(LPC_PWM1->PCR, 9) = 1;
|
||||
BITBAND(LPC_PWM1->PCR, 10) = 1;
|
||||
BITBAND(LPC_PWM1->PCR, 11) = 1;
|
||||
|
||||
led_pwmstate = 1;
|
||||
}
|
||||
|
||||
void led_std() {
|
||||
BITBAND(LPC_PINCON->PINSEL4, 1) = 0;
|
||||
BITBAND(LPC_PINCON->PINSEL4, 3) = 0;
|
||||
BITBAND(LPC_PINCON->PINSEL4, 5) = 0;
|
||||
|
||||
BITBAND(LPC_PINCON->PINSEL4, 0) = 0;
|
||||
BITBAND(LPC_PINCON->PINSEL4, 2) = 0;
|
||||
BITBAND(LPC_PINCON->PINSEL4, 4) = 0;
|
||||
|
||||
BITBAND(LPC_PWM1->PCR, 9) = 0;
|
||||
BITBAND(LPC_PWM1->PCR, 10) = 0;
|
||||
BITBAND(LPC_PWM1->PCR, 11) = 0;
|
||||
|
||||
led_pwmstate = 0;
|
||||
}
|
||||
|
||||
void led_init() {
|
||||
/* power is already connected by default */
|
||||
/* set PCLK divider to 8 */
|
||||
BITBAND(LPC_SC->PCLKSEL1, 21) = 1;
|
||||
BITBAND(LPC_SC->PCLKSEL1, 20) = 1;
|
||||
LPC_PWM1->MR0 = 255;
|
||||
BITBAND(LPC_PWM1->LER, 0) = 1;
|
||||
BITBAND(LPC_PWM1->TCR, 0) = 1;
|
||||
BITBAND(LPC_PWM1->TCR, 3) = 1;
|
||||
BITBAND(LPC_PWM1->MCR, 1) = 1;
|
||||
}
|
||||
|
||||
@ -3,6 +3,9 @@
|
||||
#ifndef _LED_H
|
||||
#define _LED_H
|
||||
|
||||
void readbright(uint8_t bright);
|
||||
void writebright(uint8_t bright);
|
||||
void rdybright(uint8_t bright);
|
||||
void readled(unsigned int state);
|
||||
void writeled(unsigned int state);
|
||||
void rdyled(unsigned int state);
|
||||
@ -11,5 +14,8 @@ void toggle_rdy_led(void);
|
||||
void toggle_read_led(void);
|
||||
void toggle_write_led(void);
|
||||
void led_panic(void);
|
||||
void led_pwm(void);
|
||||
void led_std(void);
|
||||
void led_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
@ -59,9 +59,10 @@ int main(void) {
|
||||
uart_init();
|
||||
fpga_spi_init();
|
||||
spi_preinit();
|
||||
led_init();
|
||||
/* do this last because the peripheral init()s change PCLK dividers */
|
||||
clock_init();
|
||||
|
||||
led_pwm();
|
||||
sdn_init();
|
||||
fpga_spi_init();
|
||||
printf("\n\nsd2snes mk.2\n============\nfw ver.: " VER "\ncpu clock: %d Hz\n", CONFIG_CPU_FREQUENCY);
|
||||
@ -176,7 +177,7 @@ restart:
|
||||
}
|
||||
set_mcu_ovr(0);
|
||||
snes_reset(1);
|
||||
delay_ms(100);
|
||||
delay_ms(1);
|
||||
snes_reset(0);
|
||||
break;
|
||||
case SNES_CMD_SETRTC:
|
||||
@ -221,7 +222,7 @@ restart:
|
||||
reset_count=0;
|
||||
set_mcu_ovr(1);
|
||||
snes_reset(1);
|
||||
delay_ms(100);
|
||||
delay_ms(1);
|
||||
if(romprops.ramsize_bytes && fpga_test() == FPGA_TEST_TOKEN) {
|
||||
writeled(1);
|
||||
save_sram(file_lfn, romprops.ramsize_bytes, SRAM_SAVE_ADDR);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user