add simple pwm to start

This commit is contained in:
optixx 2009-09-20 12:09:13 +02:00
parent d9b729754c
commit d86f0ad5a9
4 changed files with 38 additions and 45 deletions

View File

@ -28,9 +28,27 @@
#include "sram.h"
#include "info.h"
#include "irq.h"
#include "usbdrv.h"
extern uint32_t req_bank_size;
void usb_connect()
{
uint8_t i = 0;
info_P(PSTR("USB init\n"));
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
cli();
info_P(PSTR("USB disconnect\n"));
i = 10;
while (--i) { /* fake USB disconnect for > 250 ms */
_delay_ms(50);
}
led_on();
usbDeviceConnect();
info_P(PSTR("USB connect\n"));
}
void send_reset()
{

View File

@ -25,5 +25,6 @@
void send_reset();
void send_irq();
void set_rom_mode();
void usb_connect();
#endif

View File

@ -250,26 +250,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
*/
void usb_connect()
{
uint8_t i = 0;
info_P(PSTR("USB init\n"));
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
cli();
info_P(PSTR("USB disconnect\n"));
i = 10;
while (--i) { /* fake USB disconnect for > 250 ms */
led_on();
_delay_ms(15);
led_off();
_delay_ms(35);
}
led_on();
usbDeviceConnect();
info_P(PSTR("USB connect\n"));
}
void boot_startup_rom(uint16_t init_delay)
{
info_P(PSTR("Fetch loader rom\n"));
@ -293,7 +273,6 @@ void boot_startup_rom(uint16_t init_delay)
snes_irq_off();
snes_hirom();
snes_wr_disable();
irq_stop();
snes_bus_active();
info_P(PSTR("Activate SNES bus\n"));
@ -335,14 +314,15 @@ int main(void)
banner();
system_init();
//pwm_init();
pwm_init();
shared_memory_init();
snes_reset_hi();
snes_reset_off();
irq_init();
boot_startup_rom(500);
boot_startup_rom(50);
globals_init();
pwm_stop();
usbInit();
usb_connect();

View File

@ -28,29 +28,19 @@
#include "sram.h"
#define PWM_SINE_MAX 255
#define PWM_SINE_MAX 64
#define PWM_OVERFLOW_MAX 1024
uint8_t pwm_sine_table[] = {
0x7f,0x82,0x85,0x88,0x8b,0x8e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x2c,0x2e,0x31,0x33,0x36,0x38,0x3b,0x3e,0x40,0x43,0x46,0x49,0x4c,0x4f,0x51,
0x54,0x57,0x5a,0x5d,0x60,0x63,0x67,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7c,0x7f
0x7f,0x8b,0x97,0xa4,0xaf,0xbb,0xc5,0xcf,0xd9,0xe1,0xe8,0xef,0xf4,0xf8,0xfb,0xfd,
0xfd,0xfd,0xfb,0xf8,0xf3,0xee,0xe7,0xe0,0xd7,0xce,0xc4,0xb9,0xae,0xa2,0x96,0x89,
0x7e,0x71,0x65,0x59,0x4d,0x42,0x37,0x2d,0x24,0x1c,0x15,0x0f,0x09,0x05,0x03,0x01,
0x01,0x01,0x03,0x07,0x0b,0x11,0x17,0x1f,0x28,0x31,0x3b,0x46,0x52,0x5e,0x6a,0x76
};
volatile uint8_t pwm_setting; // Einstellungen für die einzelnen PWM-Kanäle
volatile uint8_t pwm_overflow; // Einstellungen für die einzelnen PWM-Kanäle
volatile uint16_t pwm_overflow; // Einstellungen für die einzelnen PWM-Kanäle
volatile uint8_t pwm_idx; // Einstellungen für die einzelnen PWM-Kanäle
volatile uint16_t pwm_overflow_max; // Einstellungen für die einzelnen PWM-Kanäle
ISR(TIMER2_COMPA_vect) {
static uint8_t pwm_cnt=0;
@ -65,29 +55,33 @@ uint8_t pwm_sine_table[] = {
pwm_cnt=0;
else
pwm_cnt++;
if (!pwm_overflow++){
if (pwm_overflow_max == pwm_overflow++ ){
pwm_setting = pwm_sine_table[pwm_idx++];
pwm_overflow = 0;
if (PWM_SINE_MAX == pwm_idx)
pwm_idx = 0;
}
}
void pwm_speed(uint16_t val) {
pwm_overflow_max = val;
}
void pwm_set(uint8_t val) {
pwm_setting = val;
}
void pwm_stop(void) {
while(pwm_setting!=0xfd);
//cli();
TIMSK2 = 0;
//sei();
}
void pwm_init(void) {
pwm_overflow_max = PWM_OVERFLOW_MAX;
pwm_setting = 0x7f;
pwm_overflow = 0;
//cli();
TCCR2B = 1;
TIMSK2 |= (1<<OCIE2A);
//sei();
sei();
}