예제 #1
0
파일: STMPE811.cs 프로젝트: LeTsoy/Samples
        /// <summary>
        /// Disable interrupt mode for the selected IO pin(s).
        /// </summary>
        /// <param name="pins">The IO interrupt to be enabled.</param>
        public void DisableInterrupt(IOPins pins)
        {
            byte[] buffer = new byte[1];

            // Get the IO interrupt state
            _touchController.WriteReadPartial(new byte[] { REGISTER_IO_INT_EN }, buffer);

            // Set the interrupts to be Disabled
            buffer[0] &= (byte)(~(byte)pins);

            // Write back the new value in the register
            _touchController.WritePartial(new byte[] { REGISTER_IO_INT_EN, buffer[0] });
        }
예제 #2
0
파일: STMPE811.cs 프로젝트: LeTsoy/Samples
        /// <summary>
        /// Enable the AF for the selected IO pin(s).
        /// </summary>
        /// <param name="pins">The IO pin(s) to be configured.</param>
        public void EnableAF(IOPins pins)
        {
            byte[] buffer = new byte[1];

            // Get the current state of the IO_AF register
            _touchController.WriteReadPartial(new byte[] { REGISTER_IO_AF }, buffer);

            // Enable the selected pins alternate function
            buffer[0] &= (byte)(~((byte)pins));

            // Write back the new value in IO AF register
            _touchController.WritePartial(new byte[] { REGISTER_IO_AF, buffer[0] });
        }
예제 #3
0
파일: STMPE811.cs 프로젝트: LeTsoy/Samples
        /// <summary>
        /// Start the IO functionality use and disable the AF for selected IO pin.
        /// </summary>
        /// <param name="pin">The IO pin(s) to put in AF.</param>
        public void IOStart(IOPins pin)
        {
            byte[] buffer = new byte[1];

            // Get the current register value
            _touchController.WriteReadPartial(new byte[] { REGISTER_SYS_CTRL2 }, buffer);

            // Set the Functionalities to be Disabled
            buffer[0] &= 0xBE; // equivalent to ~(IO_FCT | ADC_FCT)

            // Write the new register value
            _touchController.WritePartial(new byte[] { REGISTER_SYS_CTRL2, buffer[0] });

            // Disable AF for the selected IO pin(s)
            DisableAF(pin);
        }
예제 #4
0
파일: STMPE811.cs 프로젝트: LeTsoy/Samples
        /// <summary>
        /// Configures the IO pin according to IO mode value.
        /// </summary>
        /// <param name="pin">The output pin to be set or reset.</param>
        /// <param name="mode">The IO pin mode to configure.</param>
        public void IOConfig(IOPins pin, IOMode mode)
        {
            switch (mode)
            {
            case IOMode.Input:
                InitializePin(pin, IODirection.In);
                break;

            case IOMode.Output:
                InitializePin(pin, IODirection.Out);
                break;

            case IOMode.InterruptRisingEdge:
                EnableGlobalInterrupt();
                //EnablePinInterrupt(pin);
                InitializePin(pin, IODirection.In);
                //IOSetEdgeMode(pin, Edge.Rising);
                break;

            case IOMode.InterruptFallingEdge:
                EnableGlobalInterrupt();
                //EnablePinInterrupt(pin);
                InitializePin(pin, IODirection.In);
                //IOSetEdgeMode(pin, Edge.Falling);
                break;

            case IOMode.InterruptLowLevel:
                EnableGlobalInterrupt();
                //EnablePinInterrupt(pin);
                InitializePin(pin, IODirection.In);
                SetInterruptType(InterruptType.Level);
                SetInterruptPolarity(InterruptPolarity.Low);
                break;

            case IOMode.InterruptHighLevel:
                EnableGlobalInterrupt();
                //EnablePinInterrupt(pin);
                InitializePin(pin, IODirection.In);
                SetInterruptType(InterruptType.Level);
                SetInterruptPolarity(InterruptPolarity.High);
                break;

            default:
                throw new ArgumentException();
            }
        }
예제 #5
0
파일: STMPE811.cs 프로젝트: LeTsoy/Samples
        /// <summary>
        /// Initialize the selected IO pin direction.
        /// </summary>
        /// <param name="pin">The IO pin to be configured.</param>
        /// <param name="direction">The IO pin direction.</param>
        public void InitializePin(IOPins pin, IODirection direction)
        {
            byte[] buffer = new byte[1];

            // Get all the Pins direction
            _touchController.WriteReadPartial(new byte[] { REGISTER_IO_DIR }, buffer);

            // Set the selected pin direction
            if (direction != IODirection.In)
            {
                buffer[0] |= (byte)pin;
            }
            else
            {
                buffer[0] &= (byte)(~((byte)pin));
            }

            // Write the register with the new value
            _touchController.WritePartial(new byte[] { REGISTER_IO_DIR, buffer[0] });
        }