The $p$-adic Poincaré lemma and the period map