Changeset c8ec8ce in avrstuff


Ignore:
Timestamp:
Sep 3, 2012, 11:08:47 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
41d46ae
Parents:
8659a17
Message:
  • debug leds
  • fix read and write code (still not working !)

git-svn-id: svn://pulkomandy.tk/avrstuff@67 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • V-USB_Dev/firmwares/herePic/main.c

    r8659a17 rc8ec8ce  
    2727#define VPP 1
    2828
     29// VUSB leds (PD6 and PD7)
     30#define RED 64
     31#define GREEN 128
    2932
    3033// TODO is it wise to use a timer or two for bit patterns generation ? (see
     
    5659        PORTB |= VPP; // Enter programming mode
    5760
     61        // Configure leds
     62        DDRD |= RED | GREEN;
     63        PORTD |= RED | GREEN;
     64
     65        int k = 0;
     66
    5867        while(1) {
     68                if (k-- < 0)
     69                {
     70                        k = 20000;
     71                        PORTD ^= RED;
     72                }
    5973                wdt_reset();
    6074                usbPoll();
     
    6781        for(int i = 6; --i>= 0;)
    6882        {
    69                 PORTB |= PGC;
    7083                if(cmd & 1)
    7184                        PORTB |= PGD;
    7285                else
    7386                        PORTB &= ~PGD;
     87                PORTB |= PGC;
    7488                PORTB &= ~PGC;
    7589
     
    88102        for(int i = 16; --i>= 0;)
    89103        {
    90                 PORTB |= PGC;
    91104                if(data & 1)
    92105                        PORTB |= PGD;
    93106                else
    94107                        PORTB &= ~PGD;
     108                PORTB |= PGC;
    95109                PORTB &= ~PGC;
    96110
     
    105119        ICSP_command(cmd);
    106120
     121        // PGD as input
     122        DDRB &= ~PGD;
     123        PORTB |= PGD; //pull up
     124
    107125        // get data
    108126        for(int i = 16; --i>= 0;)
    109127        {
    110128                PORTB |= PGC;
    111                 *data |= (PORTB & PGD) / PGD;
     129                *data |= (PINB & PGD) / PGD;
    112130                PORTB &= ~PGC;
    113131
     
    115133        }
    116134        _delay_us(1);
     135
     136        // PGD as output
     137        PORTB &= ~PGD;
     138        DDRB |= PGD;
    117139}
    118140
     
    121143        usbRequest_t *rq = (void *)data;
    122144
     145        PORTD &= ~GREEN;
     146
     147        if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR)
    123148        switch(rq->bRequest)
    124149        {
     
    138163
    139164                        // Return the number of bytes we wrote (none here)
     165                        PORTD |= GREEN;
    140166                        return 0;
    141167                }
     
    153179
    154180                        // send the command
    155                         ICSP_command(command);
    156 
     181                        ICSP_write(command, 0);
     182
     183                        PORTD |= GREEN;
    157184                        return 0;
    158185                }
     
    167194                        usbMsgPtr = (uint8_t*)&ICSP_data;
    168195
     196                        PORTD |= GREEN;
    169197                        return 2; // We send 2 bytes back
    170198                }
    171199        }
     200
     201        // Unhandled commands leave the green led on.
    172202        return 0;
    173203}
Note: See TracChangeset for help on using the changeset viewer.