Пт июл 28, 2017 23:32:56
Сб июл 29, 2017 09:37:30
Сб июл 29, 2017 10:24:22
Пн июл 31, 2017 22:58:16
Сб авг 05, 2017 11:38:57
Пн сен 04, 2017 12:15:10
Пн сен 04, 2017 12:20:22
Пн сен 04, 2017 15:20:05
Пн сен 04, 2017 15:47:46
Пн сен 04, 2017 19:28:35
Пн сен 04, 2017 20:27:22
Пн сен 04, 2017 20:56:09
Пн сен 04, 2017 22:06:35
void Endpoint::activate()
{
if (is_in)
{
USBxDev()->DAINTMSK |= USB_OTG_DAINTMSK_IEPM & (1 << num);
if (!(in(num)->DIEPCTL & USB_OTG_DIEPCTL_USBAEP))
{
in(num)->DIEPCTL |= (maxPacket & USB_OTG_DIEPCTL_MPSIZ) | (uint32_t(type) << 18) |
(num << 22) | USB_OTG_DIEPCTL_SD0PID_SEVNFRM | USB_OTG_DIEPCTL_USBAEP;
}
}
else
{
USBxDev()->DAINTMSK |= USB_OTG_DAINTMSK_OEPM & ((1 << num) << 16);
if (!(out(num)->DOEPCTL & USB_OTG_DOEPCTL_USBAEP))
{
out(num)->DOEPCTL |= (maxPacket & USB_OTG_DOEPCTL_MPSIZ) | (uint32_t(type) << 18) |
USB_OTG_DIEPCTL_SD0PID_SEVNFRM | USB_OTG_DOEPCTL_USBAEP;
}
}
}
auto USBxDev() { return (USB_OTG_DeviceTypeDef*)((uint32_t)hpcd.Instance + USB_OTG_DEVICE_BASE); }
auto Endpoint::in(uint32_t i)
{
return (USB_OTG_INEndpointTypeDef*)((uint32_t)hpcd->Instance + USB_OTG_IN_ENDPOINT_BASE + i * USB_OTG_EP_REG_SIZE);
}
auto Endpoint::out(uint32_t i)
{
return (USB_OTG_OUTEndpointTypeDef*)((uint32_t)hpcd->Instance + USB_OTG_OUT_ENDPOINT_BASE + i * USB_OTG_EP_REG_SIZE);
}
void Endpoint::activate()
{
setType(type);
setAddr(num);
if (is_in)
{
btableGet(0) = (pmaadress >> 1) << 1; //setTxAddr(pmaadress);
clearTxDTOG();
setStatus(EpTxStatus::Nak);
}
else
{
btableGet(4) = (pmaadress >> 1) << 1; //setRxAddr(pmaadress);
setCntRxReg(rxCnt(), maxpacket);
clearRxDTOG();
setStatus(EpRxStatus::Valid);
}
}
volatile uint16_t& epref() { return *(&USB->EP0R + num * 2); }
void Endpoint::setType(EpType type)
{
epref() = epref() & USB_EP_T_MASK | uint16_t(type);
}
void Endpoint::setAddr(uint16_t bAddr)
{
epref() = USB_EP_CTR_RX | USB_EP_CTR_TX | (epref() & USB_EPREG_MASK) | bAddr;
}
uint32_t& Endpoint::btableGet(uint32_t offset)
{
return *(uint32_t*)((USB->BTABLE + num * 8 + offset) * 2 + ((uint32_t)USB + 0x400));
}
void Endpoint::clearTxDTOG()
{
if (epref() & USB_EP_DTOG_TX)
{
epref() = epref() & USB_EPREG_MASK | USB_EP_CTR_RX | USB_EP_CTR_TX | USB_EP_DTOG_TX;
}
}
void Endpoint::clearRxDTOG()
{
if (epref() & USB_EP_DTOG_RX)
{
epref() = epref() & USB_EPREG_MASK | USB_EP_CTR_RX | USB_EP_CTR_TX | USB_EP_DTOG_RX;
}
}
void Endpoint::setStatus(EpTxStatus state)
{
uint16_t regVal = epref() & USB_EPTX_DTOGMASK;
if (USB_EPTX_DTOG1 & uint32_t(state)) regVal ^= USB_EPTX_DTOG1;
if (USB_EPTX_DTOG2 & uint32_t(state)) regVal ^= USB_EPTX_DTOG2;
epref() = regVal | USB_EP_CTR_RX | USB_EP_CTR_TX;
}
void Endpoint::setStatus(EpRxStatus state)
{
uint16_t regVal = epref() & USB_EPRX_DTOGMASK;
if (USB_EPRX_DTOG1 & uint32_t(state)) regVal ^= USB_EPRX_DTOG1;
if (USB_EPRX_DTOG2 & uint32_t(state)) regVal ^= USB_EPRX_DTOG2;
epref() = regVal | USB_EP_CTR_RX | USB_EP_CTR_TX;
}
void Endpoint::setCntRxReg(uint32_t& reg, uint32_t wCount)
{
uint16_t wNBlocks;
(wCount > 62) ? calcBLK32(reg, wCount, wNBlocks) : calcBLK2(reg, wCount, wNBlocks);
}
void Endpoint::calcBLK32(uint32_t& reg, uint32_t wCount, uint32_t wNBlocks)
{
wNBlocks = wCount >> 5;
if (!(wCount & 0x1F)) wNBlocks--;
reg = (uint16_t)((wNBlocks << 10) | 0x8000);
}
void Endpoint::calcBLK2(uint32_t& reg, uint32_t wCount, uint32_t wNBlocks)
{
wNBlocks = wCount >> 1;
if (wCount & 1) wNBlocks++;
reg = (uint16_t)(wNBlocks << 10);
}
Вт сен 05, 2017 06:12:33
Вт сен 05, 2017 09:02:51
Вт сен 05, 2017 17:33:43
Ср окт 11, 2017 21:41:11
Вс янв 14, 2018 11:56:03
Ср июл 18, 2018 19:37:30
Чт июл 19, 2018 12:33:53