Prusa MINI Firmware overview
AddressPoolImpl< MAX_DEVICES_ALLOWED > Class Template Reference

#include <address.h>

Inheritance diagram for AddressPoolImpl< MAX_DEVICES_ALLOWED >:
Collaboration diagram for AddressPoolImpl< MAX_DEVICES_ALLOWED >:

Public Member Functions

 AddressPoolImpl ()
 
virtual UsbDeviceGetUsbDevicePtr (uint8_t addr)
 
void ForEachUsbDevice (UsbDeviceHandleFunc pfunc)
 
virtual uint8_t AllocAddress (uint8_t parent, bool is_hub=false, uint8_t port=0)
 
virtual void FreeAddress (uint8_t addr)
 

Constructor & Destructor Documentation

◆ AddressPoolImpl()

template<const uint8_t MAX_DEVICES_ALLOWED>
AddressPoolImpl< MAX_DEVICES_ALLOWED >::AddressPoolImpl ( )
166  : hubCounter(0) {
167  // Zero address is reserved
168  InitEntry(0);
169 
170  thePool[0].address.devAddress = 0;
171  thePool[0].epinfo = &dev0ep;
172  dev0ep.epAddr = 0;
173  dev0ep.maxPktSize = 8;
174  dev0ep.bmSndToggle = 0; // Set DATA0/1 toggles to 0
175  dev0ep.bmRcvToggle = 0;
176  dev0ep.bmNakPower = USB_NAK_MAX_POWER;
177 
178  InitAllAddresses();
179  }

Member Function Documentation

◆ GetUsbDevicePtr()

template<const uint8_t MAX_DEVICES_ALLOWED>
virtual UsbDevice* AddressPoolImpl< MAX_DEVICES_ALLOWED >::GetUsbDevicePtr ( uint8_t  addr)
virtual

Implements AddressPool.

183  {
184  if (!addr) return thePool;
185  uint8_t index = FindAddressIndex(addr);
186  return index ? thePool + index : nullptr;
187  }

◆ ForEachUsbDevice()

template<const uint8_t MAX_DEVICES_ALLOWED>
void AddressPoolImpl< MAX_DEVICES_ALLOWED >::ForEachUsbDevice ( UsbDeviceHandleFunc  pfunc)
191  {
192  if (pfunc) {
193  for (uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
194  if (thePool[i].address.devAddress)
195  pfunc(thePool + i);
196  }
197  }
Here is the caller graph for this function:

◆ AllocAddress()

template<const uint8_t MAX_DEVICES_ALLOWED>
virtual uint8_t AddressPoolImpl< MAX_DEVICES_ALLOWED >::AllocAddress ( uint8_t  parent,
bool  is_hub = false,
uint8_t  port = 0 
)
virtual

Implements AddressPool.

201  {
202  /* if (parent != 0 && port == 0)
203  USB_HOST_SERIAL.println("PRT:0"); */
204  UsbDeviceAddress _parent;
205  _parent.devAddress = parent;
206  if (_parent.bmReserved || port > 7)
207  //if(parent > 127 || port > 7)
208  return 0;
209 
210  if (is_hub && hubCounter == 7) return 0;
211 
212  // finds first empty address entry starting from one
213  uint8_t index = FindAddressIndex(0);
214 
215  if (!index) return 0; // if empty entry is not found
216 
217  if (_parent.devAddress == 0) {
218  if (is_hub) {
219  thePool[index].address.devAddress = 0x41;
220  hubCounter++;
221  }
222  else
223  thePool[index].address.devAddress = 1;
224 
225  return thePool[index].address.devAddress;
226  }
227 
228  UsbDeviceAddress addr;
229  addr.devAddress = 0; // Ensure all bits are zero
230  addr.bmParent = _parent.bmAddress;
231  if (is_hub) {
232  addr.bmHub = 1;
233  addr.bmAddress = ++hubCounter;
234  }
235  else {
236  addr.bmHub = 0;
237  addr.bmAddress = port;
238  }
239  thePool[index].address = addr;
240  /*
241  USB_HOST_SERIAL.print("Addr:");
242  USB_HOST_SERIAL.print(addr.bmHub, HEX);
243  USB_HOST_SERIAL.print(".");
244  USB_HOST_SERIAL.print(addr.bmParent, HEX);
245  USB_HOST_SERIAL.print(".");
246  USB_HOST_SERIAL.println(addr.bmAddress, HEX);
247  */
248  return thePool[index].address.devAddress;
249  }

◆ FreeAddress()

template<const uint8_t MAX_DEVICES_ALLOWED>
virtual void AddressPoolImpl< MAX_DEVICES_ALLOWED >::FreeAddress ( uint8_t  addr)
virtual

Implements AddressPool.

253  {
254  // if the root hub is disconnected all the addresses should be initialized
255  if (addr == 0x41) {
256  InitAllAddresses();
257  return;
258  }
259  FreeAddressByIndex(FindAddressIndex(addr));
260  }
EpInfo::bmSndToggle
uint8_t bmSndToggle
Definition: address.h:46
UsbDeviceAddress::bmReserved
uint8_t bmReserved
Definition: address.h:69
i
uint8_t i
Definition: screen_test_graph.c:72
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:39
UsbDeviceAddress
Definition: address.h:63
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:48
UsbDeviceAddress::devAddress
uint8_t devAddress
Definition: address.h:71
UsbDeviceAddress::bmParent
uint8_t bmParent
Definition: address.h:67
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:33
EpInfo::bmRcvToggle
uint8_t bmRcvToggle
Definition: address.h:47
UsbDevice::address
UsbDeviceAddress address
Definition: address.h:81
uint8_t
const uint8_t[]
Definition: 404_html.c:3
address
UsbDeviceAddress address
Definition: address.h:202
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:40
UsbDeviceAddress::bmAddress
uint8_t bmAddress
Definition: address.h:66
UsbDeviceAddress::bmHub
uint8_t bmHub
Definition: address.h:68
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:80