Esempio n. 1
0
        //private static uint EAPI_GPIO_BANK_MASK(uint GPIO_NUM)
        //{
        //    return (uint) (1 << (int)((GPIO_NUM) & 0x1F));
        //}
        //#define EAPI_GPIO_BANK_TEST_STATE(GPIO_NUM, TState, TValue) \ (((TValue>>((GPIO_NUM)&0x1F))&1)==(TState))

        internal GpioCapability GetGpioCapabilities()
        {
            uint inputCapabilityMask  = 0;
            uint outputCapabilityMask = 0;
            bool isUnsupported        = false;

            if (_gpioCapability != null)
            {
                return(_gpioCapability);
            }

            uint resultCode = EApiGPIOGetDirectionCaps(_eapiIdGpioBank00, ref inputCapabilityMask, ref outputCapabilityMask);

            if (_eApiStatusCodes.IsUnsupported(resultCode))
            {
                _logger.Warning(_eapiIdGpioBank00 + " EApiGPIOGetDirectionCaps is unsupported");
                isUnsupported = true;
            }
            if (!_eApiStatusCodes.IsSuccess(resultCode))
            {
                _logger.Warning("EApiGPIOGetDirectionCaps: " + _eApiStatusCodes.GetStatusStringFrom(resultCode));
                isUnsupported = true;
            }

            _gpioCapability = new GpioCapability(inputCapabilityMask, outputCapabilityMask, isUnsupported);
            _logger.Information("EApiGPIOGetDirectionCaps: " + _gpioCapability);
            return(_gpioCapability);
        }
Esempio n. 2
0
        public void SetLevel(EapiGpioId id, GpioLevelEnum levelEnum)
        {
            GpioCapability gpioCapabilities = GetGpioCapabilities();

            if (!gpioCapabilities.IsOutput(id))
            {
                throw new Exception(id + " is not an output");
            }
            uint bitmask = (uint)(gpioCapabilities.OutputCapabilityMask & (1 << (int)id));

            int newLevelVAlues = (int)ReadGpioRegister();

            if (levelEnum == GpioLevelEnum.EapiGpioHigh)
            {
                newLevelVAlues |= 1 << (int)id;
            }
            else
            {
                newLevelVAlues &= ~(1 << (int)id);
            }

            _logger.Information("SetLevel {0} to {1} =>  bitmask={2}, newLevelVAlues={3}", id, levelEnum, Convert.ToString(bitmask, 2), Convert.ToString(newLevelVAlues, 2));


            uint resultCode = EApiGPIOSetLevel(_eapiIdGpioBank00, bitmask, (uint)(0xffff & newLevelVAlues));

            if (!_eApiStatusCodes.IsSuccess(resultCode))
            {
                throw new Exception("EApiGPIOSetLevel: " + _eApiStatusCodes.GetStatusStringFrom(resultCode));
            }
        }
Esempio n. 3
0
        public void SetAll(GpioLevelEnum levelEnum)
        {
            GpioCapability gpioCapabilities = GetGpioCapabilities();
            uint           bitmask          = gpioCapabilities.OutputCapabilityMask;

            uint newLevelValues = (uint)(levelEnum == GpioLevelEnum.EapiGpioHigh ? 0xffff : 0);

            _logger.Information("SetAll: id={0}, bitmask={1}, new level={2}", _eapiIdGpioBank00, bitmask.ToBinaryString(), newLevelValues.ToBinaryString());

            uint resultCode = EApiGPIOSetLevel(_eapiIdGpioBank00, bitmask, newLevelValues);

            if (!_eApiStatusCodes.IsSuccess(resultCode))
            {
                throw new Exception("EApiGPIOSetLevel: " + _eApiStatusCodes.GetStatusStringFrom(resultCode));
            }
        }
Esempio n. 4
0
        private uint ReadGpioRegister()
        {
            GpioCapability gpioCapabilities = GetGpioCapabilities();

            if (gpioCapabilities.IsUnsupported)
            {
                return(0);
            }

            uint bitmask    = gpioCapabilities.InputCapabilityMask | gpioCapabilities.OutputCapabilityMask;
            uint level      = 0;
            uint resultCode = EApiGPIOGetLevel(_eapiIdGpioBank00, bitmask, ref level);

            if (!_eApiStatusCodes.IsSuccess(resultCode))
            {
                throw new Exception("EApiGPIOGetLevel: " + _eApiStatusCodes.GetStatusStringFrom(resultCode));
            }
            _logger.Information("GetLevel: id={0}, bitmask={1}, levelEnum={2}", _eapiIdGpioBank00, bitmask.ToBinaryString(), level.ToBinaryString());
            return(level);
        }