 
         guard let mailbox = mailbox else {fatalError("Could allocate mailbox.")}
 
-        dma_cb = mailbox.baseVirtualAddress.assumingMemoryBound(to: DMACallback.self)
-        pwm_raw = (mailbox.baseVirtualAddress + MemoryLayout<DMACallback>.stride).assumingMemoryBound(to: UInt.self)
+        dmaCallbackPointer = mailbox.baseVirtualAddress.assumingMemoryBound(to: DMACallback.self)
+        pwmRawPointer = (mailbox.baseVirtualAddress + MemoryLayout<DMACallback>.stride).assumingMemoryBound(to: UInt.self)
 
         // Fill PWM buffer with zeros
-        let rows = (mboxsize - MemoryLayout<DMACallback>.stride) / MemoryLayout<UInt>.stride
+        let rows = dataSize / MemoryLayout<UInt>.stride
         for pos in 0..<rows {
-            pwm_raw.advanced(by: pos).pointee = 0
-        }
-    }
-
-    internal func sendDataWithPattern(values: [UInt8]) {
-
-        guard symbolBits > 0 else {fatalError("Couldn't generate a valid pattern for the provided duty cycle values, try with more spaced values.")}
+            pwmRawPointer.advanced(by: pos).pointee = 0
+        }
 
         // Stop PWM and clock
         pwmBasePointer.pointee = 0

    func initPWM()
    func startPWM(period ns: Int, duty percent: Int)
    func stopPWM()
}

public class HardwarePWM: PWMOutput {

        clockBasePointer.advanced(by: 40).pointee = CLKM_PASSWD | CLKM_CTL_KILL     //Set KILL flag
        usleep(10)

        // Configure clock
        let idiv = calculateUnscaledDIVI(base: .Oscillator, desired: UInt(symbolBits * patternFrequency))
        clockBasePointer.advanced(by: 41).pointee = CLKM_PASSWD | (idiv << CLKM_DIV_DIVI)            //Set DIVI value  
        clockBasePointer.advanced(by: 40).pointee = CLKM_PASSWD | CLKM_CTL_ENAB | CLKM_CTL_SRC_OSC   //Enable clock, MASH 0, source OSC
        usleep(10)

        // Configure PWM 
        pwmBasePointer.advanced(by: 4).pointee = 32         // RNG1: 32-bits per word to serialize
        usleep(10)
        pwmBasePointer.pointee = PWMCTL_CLRF1
        usleep(10)
        pwmBasePointer.advanced(by: 2).pointee = PWMDMAC_ENAB | 7 << PWMDMAC_PANIC | 3 << PWMDMAC_DREQ
        usleep(10)
        pwmBasePointer.pointee = PWMCTL_USEF1 | PWMCTL_MODE1 //| PWMCTL_USEF2 | PWMCTL_MODE2 // For 2nd chan 
        usleep(10)
        pwmBasePointer.pointee |= PWMCTL_PWEN1               //| PWMCTL_PWEN2 // For 2nd chan 

        // Initialize the DMA control block
        dmaCallbackPointer.pointee = DMACallback(
                ti: DMATI_NO_WIDE_BURSTS |              // 32-bit transfers
                     DMATI_WAIT_RESP |                  // wait for write complete
                     DMATI_DEST_DREQ |                  // user peripheral flow control
                     UInt32(0x5  << DMATI_PERMAP) |     // PWM peripheral
                     DMATI_SRC_INC,                     // Increment src addr
                source_ad: UInt32(mailbox.virtualTobaseBusAddress(UnsafeMutableRawPointer(pwmRawPointer))),
                dest_ad: UInt32(PWM_PHY_BASE + 0x18),   // PWM FIF1 Register, shared between channels
                txfr_len: UInt32(dataSize),
                stride: 0,
                nextconbk: 0)

        dmaBasePointer.pointee = 0                  //0 CS
        dmaBasePointer.advanced(by: 5).pointee = 0  //0 TXFR_LEN

    }

    public func sendDataWithPattern(values: [UInt8]) {

        guard symbolBits > 0 else {fatalError("Couldn't generate a valid pattern for the provided duty cycle values, try with more spaced values.")}

        dma_wait()
        
        let stream = dataToBitStream(data: values, zero: zeroPattern, one: onePattern, width: symbolBits)

        func printBinary(_ value: UInt32) {
