Skip to content
php-baremetal REGISTRY
Publish a package

php-baremetal/rtc-pcf85063

bm-lib MIT

PCF85063 real-time clock driver for ext-i2c (Baremetal\I2c\Driver\Pcf85063).

bus: i2c

IDE stubs @ 1.1.0

The PHP declarations of the functions, classes and constants this package adds, with their docblocks, so PhpStorm and Intelephense can complete and type-check your firmware code.

You don't need to download them: on every composer install and composer update, conductor copies them into vendor/php-baremetal/ide-stubs/, which IDEs index without configuration. They are never loaded at runtime.

php ide/rtc-pcf85063.stub
<?php
// php-baremetal/rtc-pcf85063 1.1.0 — IDE helper, not loaded at runtime.

namespace Baremetal\I2c\Driver {
    /**
     * A PCF85063 real-time clock: extends Baremetal\I2c\Device and implements no capability interface.
     *
     * All the Device methods work on it, except that it has no sampler: poll(), sample() and drain() throw "this
     * device has no poller (driver has no poll block)". The clock runs in 24-hour mode.
     */
    class Pcf85063 extends \Baremetal\I2c\Device
    {
        /**
         * Attaches the chip, reads Control_1 and writes it back with the STOP, software-reset, test and 12-hour
         * bits cleared: the clock runs in 24-hour mode, and the crystal load setting is left as the board set it.
         *
         * Constructing it again with the same bus and address returns a handle to the same device without
         * writing again.
         *
         * @param \Baremetal\I2c\Bus $bus The bus the chip is wired to.
         * @param int $address 7-bit address; the chip has a fixed address.
         * @param int $hz SCL clock for this device in Hz: 0 uses 400 kHz, otherwise 1 to 1000000.
         * @throws \ValueError When $hz is negative or above 1000000, or $address is outside 0x08 to 0x77.
         * @throws \Exception "cannot init pcf85063 at 0x..: ..." (the Control_1 read or write failed, for example
         *                    with no chip), or "address 0x.. on this bus is already used by another driver".
         */
        public function __construct(\Baremetal\I2c\Bus $bus, int $address = 0x51, int $hz = 400000) {}

        /**
         * Reads the seven time registers in one transaction.
         *
         * @return array ['year' => 2000 to 2099, 'month' => 1 to 12, 'day' => 1 to 31, 'hour' => 0 to 23,
         *               'minute' => 0 to 59, 'second' => 0 to 59 (all int), 'valid' => bool, false when the
         *               oscillator-stopped flag is set].
         * @throws \Exception "PCF85063 read failed".
         */
        public function now(): array {}

        /**
         * Writes the date and time in one transaction, with the weekday computed from the date.
         *
         * Every argument is checked first; a value out of range writes nothing. Writing the seconds clears the
         * oscillator-stopped flag, so now()['valid'] becomes true.
         *
         * @param int $year The year, 2000 to 2099 (the chip stores two digits).
         * @param int $month The month, 1 to 12.
         * @param int $day The day of that month (29 February only in leap years).
         * @param int $hour The hour, 0 to 23.
         * @param int $minute The minute, 0 to 59.
         * @param int $second The second, 0 to 59.
         * @return void
         * @throws \ValueError "...: Argument #1 ($year) must be between 2000 and 2099", "...: Argument #2
         *                     ($month) must be between 1 and 12", "...: Argument #3 ($day) is not a day of that
         *                     month", "...: Argument #4 ($hour) must be between 0 and 23", or "...: Argument #5
         *                     ($minute) / #6 ($second) must be between 0 and 59".
         * @throws \Exception "PCF85063 write failed".
         */
        public function set(int $year, int $month, int $day, int $hour, int $minute, int $second): void {}
    }
}
Download rtc-pcf85063.php