Exemplo n.º 1
0
        public static void InitializeCpuIO()
        {
            if (chipSelectPin == null)
            {
                chipSelectPin = GpioController.GetDefault().OpenPin(CS_PIN_NUM);
                chipSelectPin.SetDriveMode(GpioPinDriveMode.Output);
                chipSelectPin.Write(GpioPinValue.High);
            }

            Spi.InitSpi();     /* Initialize ports to control MMC */
        }
Exemplo n.º 2
0
        /*-----------------------------------------------------------------------*/
        /* Select the card and wait for ready                                    */
        /*-----------------------------------------------------------------------*/

        static int select()     /* 1:OK, 0:Timeout */
        {
            /* Set CS# low */
            chipSelectPin.Write(GpioPinValue.Low);
            Spi.RcvSpi();                   /* Dummy clock (force DO enabled) */
            if (wait_ready() > 0)
            {
                return(1);                  /* Wait for card ready */
            }
            deselect();
            return(0);                               /* Failed */
        }
Exemplo n.º 3
0
        /*-----------------------------------------------------------------------*/
        /* Receive bytes from the card                                           */
        /*-----------------------------------------------------------------------*/

        static void rcvr_mmc(
            ref byte[] buff,    /* Pointer to read buffer */
            uint bc             /* Number of bytes to receive */
            )
        {
            int rxIndex = 0;

            do
            {
                buff[rxIndex++] = Spi.RcvSpi();     /* Store a received byte */
            }while (--bc > 0);
        }
Exemplo n.º 4
0
        static byte CardType;          /* b0:MMC, b1:SDv1, b2:SDv2, b3:Block addressing */



        /*-----------------------------------------------------------------------*/
        /* Transmit bytes to the card                                            */
        /*-----------------------------------------------------------------------*/

        static void xmit_mmc(
            byte[] buff,    /* Data to be sent */
            uint bc         /* Number of bytes to send */
            )
        {
            byte d;
            int  bufIndex = 0;

            do
            {
                d = buff[bufIndex++];         /* Get a byte to be sent */
                Spi.XmitSpi(d);
            } while (bufIndex < bc);
        }
Exemplo n.º 5
0
        /*-----------------------------------------------------------------------*/
        /* Deselect the card and release SPI bus                                 */
        /*-----------------------------------------------------------------------*/

        static void deselect()
        {
            chipSelectPin.Write(GpioPinValue.High);
            Spi.RcvSpi();       /* Dummy clock (force DO hi-z for multiple slave SPI) */
        }